I want to use CouchDB as database-backend in a NodeJS app with Typescript. CouchDb-Nano is used for this, since it provides the required Typings. So I installed both packages:
"devDependencies": {
"@types/nano": "^6.4.5"
},
"dependencies": {
"nano": "^6.4.3"
}
I found this question for the correct TS import syntax. It doesn't work for me. By playing around, I found the following compiling:
import Nano from "nano";
let nano = Nano("http://localhost:5984");
But my intellisens in VS code seems totally different. For example, the docs say that nano has a attribute called db
which several methods like this for selecting a database:
var alice = nano.db.use('alice');
This code gave me a error, that no attribute called db
exists. Intellisense show me only auth, config, session
as attributes:
VS Code intellisense screenshot
According to the comment-header, the typings are for couchdb-nano (no other project which is called nano, too) and also for version 6.4, which is used here.
So what I'm doing wrong?
Looks like you should be able to cast the Nano function to the ServerScope interface and then intellisense should work when interacting with your nano object.
import Nano, { ServerScope } from "nano";
const nano = Nano("http://localhost:5984") as ServerScope;
const alice = nano.db.use("alice");