不能使用带有Typescript的pouchdb吗?类型问题?

问题描述 投票:1回答:3

我正在尝试在typescript(离子)应用程序中安装pouchdb。这些类型不起作用

npm install --save pouchdb
npm install --save-dev @types/pouchdb

当我尝试使用它(从'pouchdb'导入Pouchdb)时,我收到此错误

src / app / services / pouchdb.service.ts(3,8)中的错误:错误TS1192:模块'“C:/ Users / User / PROG / toto / node_modules / @ types / pouchdb / index”'没有默认导出。

我试过了

import * as Pouchdb from 'pouchdb'

错误消失在这里,但出现之后,我仍然无法使用pouchdb函数。

有解决方案吗?

typescript typescript-typings pouchdb definitelytyped
3个回答
0
投票
const PouchDB = require('pouchdb').default;

这对我有用。


1
投票

你见过这个吗? https://pouchdb.com/guides/setup-pouchdb.html#typescript

tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true
  }
}

然后在TypeScript中:

import PouchDB from 'pouchdb';

0
投票

我也在使用Ionic 4,PouchDB和pouchdb-find。以下对我有用:

npm install pouchdb @ types / pouchdb

npm install pouchdb-find @ types / pouchdb-find

在tsconfig.json中我添加了以下内容:

{
  {
    "compilerOptions": {
        "allowSyntheticDefaultImports": true
  }
}

然后在我使用pouchdb和pouchdb-find的提供程序中,我添加了以下两行:

const PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-find'));
© www.soinside.com 2019 - 2024. All rights reserved.