How do I use pouchdb with typescript?

user2302244 picture user2302244 · Jun 3, 2016 · Viewed 7.1k times · Source

I am trying to use pouchdb with Typescript. I cannot link to the pouchdb module.

import { PouchDB } from "pouchdb"

reports that it cannot find module pouchdb, even though it is in node_modules.

I also cannot find the appropriate typings for pouchdb.

Answer

leetheguy picture leetheguy · Feb 12, 2017

I'm doing this in Ionic, so I may be missing a step on getting the types file loaded properly.

Make sure your types are installed with:

npm install --save-dev @types/pouchdb

At the top of your data service import pouch like so:

import * as PouchDB from 'pouchdb';

* edit *

I don't have all the facts, but this is my current understanding. Typings is no longer needed in Typescript >2.0 I believe typescript now works automatically with types files installed from DefinitelyTyped. DefinitelyTyped is an official central repository that is kept current like npm. And even if I'm dead wrong about all this, DefinitelyTyped is still better than typings and has a much bigger community.