【问题标题】:Typescript - Cannot use 'new' with an expression whose type lacks a call or construct signatureTypescript - 不能将“new”与类型缺少调用或构造签名的表达式一起使用
【发布时间】:2018-02-06 16:44:59
【问题描述】:

我正在尝试连接到 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;
    }

【问题讨论】:

    标签: angular typescript pouchdb


    【解决方案1】:

    @types/pouchdb 在这种情况下可能会有所帮助。

    【讨论】:

      【解决方案2】:

      你可能需要 pouchdb 如下:

      import * as PouchDB from "pouchdb";
      

      然后可以做:

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

      【讨论】:

        猜你喜欢
        • 2015-09-22
        • 2017-03-25
        • 1970-01-01
        • 2021-01-04
        • 2017-01-29
        • 2018-02-09
        • 2018-10-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多