【问题标题】:TypeScript: Implement interface with both call signature and constructor signatureTypeScript:使用调用签名和构造函数签名实现接口
【发布时间】:2018-09-14 09:04:23
【问题描述】:

是否可以创建一个实现以下接口的对象:

interface I {
    (): string;
    new(): any;
}

我看到可以从这个问题中实现一个具有调用签名和一些字段的接口:Implementing TypeScript interface with bare function signature plus other fields

【问题讨论】:

    标签: typescript types


    【解决方案1】:

    环顾四周,一个对象显然有可能实现带有构造函数签名和调用签名的接口:

    https://github.com/Microsoft/TypeScript/blob/master/lib/lib.d.ts#L142 就是一个例子。

    底层函数似乎是相同的,尽管以两种不同的方式调用:

    new Object(3);
    

    Object(3);
    

    【讨论】:

      猜你喜欢
      • 2013-05-06
      • 2018-09-15
      • 1970-01-01
      • 2019-09-11
      • 1970-01-01
      • 2019-08-17
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多