Reputation: 403
Augmenting window object fails to compile with typescript 3.5.3.
Before upgrading typescript, it had worked.
// somescript.ts
declare global {
/* tslint:disable */
type Window = {
_TEST_PROP?: any
}
/* tslint:enable */
}
//someOtherScript.ts
window._TEST_PROP = {
foo: 'bar'
}
Error: Property '_TEST_PROP' does not exist on type 'Window'.
I expect it not to fail compilation, as it had already worked before
Upvotes: 0
Views: 302
Reputation: 250366
Not sure if this ever worked without errors, i expect it did not. Type aliases don't merge, interfaces do. Window
is an interface, so you can augment it.
// somescript.ts
declare global {
interface Window {
_TEST_PROP?: any
}
}
//someOtherScript.ts
window._TEST_PROP = {
foo: 'bar'
}
Upvotes: 1