不能在 TypeScript 中使用 pouchdb?是类型问题吗?
我正在尝试在一个 TypeScript(Ionic)应用中安装 pouchdb。类型不起作用
npm install --save pouchdb
npm install --save-dev @types/pouchdb
当我尝试使用它(import Pouchdb from '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 的功能。
有解决办法吗?
答案#1
你看过这个吗?https://pouchdb.com/guides/setup-pouchdb.html#typescript
在 tsconfig.json 中:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
然后在 TypeScript 中:
import PouchDB from 'pouchdb';
答案#2
const PouchDB = require('pouchdb').default;
这对我有效。
