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 } 

(code in playground)

as can see need declare new method in window interface , compiler won't complain when add actual implementation.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -