Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use pouchdb with typescript?

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.

like image 927
user2302244 Avatar asked Jun 03 '16 09:06

user2302244


People also ask

How do I install PouchDB?

Install PouchDB Server Execute the following code on Node. js command prompt to install PouchDB: npm install -g pouchdb-server.

What is PouchDB used for?

PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser. PouchDB was created to help web developers build applications that work as well offline as they do online.

How does PouchDB store data?

It stores data locally using IndexedDB and WebSQL in the browser. You can also communicate with remote and local databases continuously using PouchDB without noticing any difference. It is available on GitHub and on other open source application.


1 Answers

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.

like image 190
leetheguy Avatar answered Sep 24 '22 02:09

leetheguy