如何在TypeScript中提供缺少的声明?
如何在TypeScript中为静态类函数提供附加声明?例如,我将Chrome Canary与实验性的如何在TypeScript中提供缺少的声明?,typescript,Typescript,如何在TypeScript中为静态类函数提供附加声明?例如,我将Chrome Canary与实验性的Object.observe()JavaScript函数一起使用。为了使用它(不诉诸任何强制转换),我想声明对象。观察函数。我该怎么做 declare ?; // What goes here? var x = {}; Object.observe( x, ( update : any ) => { console.log("Hello"); } ); // Declaration nee
Object.observe()
JavaScript函数一起使用。为了使用它(不诉诸任何强制转换),我想声明对象。观察函数。我该怎么做
declare ?; // What goes here?
var x = {};
Object.observe( x, ( update : any ) => { console.log("Hello"); } ); // Declaration needed
您需要创建一个接口:
interface Object {
observe(beingObserved: any, callback: (update: any) => any) : void;
}
然后在.ts
文件中引用该接口。从0.8.1.1
开始,Intellisense有点脆弱,但它可以工作,并将在编译期间强制执行契约
它还将突出显示您使用对象的位置。使用不明确的调用表达式观察
——无法选择重载
,但它仍将编译