How do I provide additional declaration to static class functions in TypeScript? For example, I am using Chrome Canary with the experimental Object.observe() JavaScript function. In order to use it (without resorting to an any cast), I want to declare the Object.observe function. How do I do this?
declare ?; // What goes here?
var x = {};
Object.observe( x, ( update : any ) => { console.log("Hello"); } ); // Declaration needed
You’ll need to create an interface:
Then just reference that interface in your
.tsfile. As of0.8.1.1, Intellisense is kind of flaky, but it works and will enforce the contract during compile.It will also highlight the places where you use
Object.observewithAmbiguous call expression - could not choose overload, but it will compile nonetheless.