adding property to javascript object in typescript without errors -
i found this article quite interesting, not me when try extend global variable window
.
test.ts
window.test = {}; //error: property 'test' not exist on type 'window'. (function (test) { //do stuff } (window.test)); //build: property 'test' not exist on type 'window'
error message:
error: property 'test' not exist on type 'window'.
how can solve ?
it's called declaration merging:
interface window { test(): void; } window.test = function() { // ever }
as can see need declare new method in window
interface , compiler won't complain when add actual implementation.
Comments
Post a Comment