【发布时间】:2020-01-12 01:45:03
【问题描述】:
我有一个具有此 ES6 类签名的第三方库:
class Machine {
constructor(options)
static list(callback)
create(options, callback)
}
我尝试为此类创建类型声明,但出现一些错误:
export declare class IMachine {
public constructor(opts: MachineOptions)
public static list(callback: (err?: Error, machines?: IMachine[]) => void): void
}
declare interface MachineOptions {
name: string
}
用法:
const Machine: IMachine = require('lib')
Machine.list((err: Error, machines: IMachine[]) => { } // error TS2576: Property 'list' is a static member of type 'IMachine'
const machine = new Machine({name: 'some name'}) // error TS2351: This expression is not constructable. Type 'IMachine' has no construct signatures.
我在这里做错了什么?
【问题讨论】:
标签: typescript typescript-typings