Typescript - 不能对类型缺少调用或构造签名的表达式使用“new”

时间:2017-08-29 09:31:45

标签: angular typescript pouchdb

我正在尝试连接到PouchDB数据库,我收到了错误

Typescript Cannot use 'new' with an expression whose type lacks a call or construct signature

以下是我的代码: -

var PouchDB = require("pouchdb"); 

@Injectable()
export class PouchDBService {

  private isInstantiated: boolean;
  private database: any;

  public constructor(private http: Http) {
    if(!this.isInstantiated) {

      this.database = new PouchDB("db_name"); <--error at this line
      this.isInstantiated = true;
    }

2 个答案:

答案 0 :(得分:0)

在这种情况下,

@types/pouchdb可能会有所帮助。

答案 1 :(得分:0)

您可能需要pouchdb,如下所示:

import * as PouchDB from "pouchdb";

然后可以做到:

  this.database = new PouchDB("db_name"); //should work