TypeScript Version: 3.6.2
Search Terms:
Code
This code passed the type checker in TS 3.5:
interface MyWindow extends Window {
foo: string;
}
(window as MyWindow).foo = 'bar';
but fails with this error in TS 3.6:
Conversion of type 'Window & typeof globalThis' to type 'MyWindow' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'foo' is missing in type 'Window & typeof globalThis' but required in type 'MyWindow'.ts(2352)
Following the release notes, I can work around the issue by changing from interface to type and using an intersection:
type MyWindow = (typeof window) & {
foo: string;
}
(window as MyWindow).foo = 'bar';
but this feels more obscure than the old way. Is this WAI? What's the rationale for the non-extendable Window?
Expected behavior:
An interface should be able to extend Window.
Actual behavior:
The error above.
Playground Link: 3.6 isn't on the playground yet.
Related Issues:
TypeScript Version: 3.6.2
Search Terms:
Code
This code passed the type checker in TS 3.5:
but fails with this error in TS 3.6:
Following the release notes, I can work around the issue by changing from
interfacetotypeand using an intersection:but this feels more obscure than the old way. Is this WAI? What's the rationale for the non-extendable Window?
Expected behavior:
An interface should be able to extend
Window.Actual behavior:
The error above.
Playground Link: 3.6 isn't on the playground yet.
Related Issues: