Question about extending Window interface

Topics: General
Jun 25, 2014 at 7:13 PM
Is there any way to get the TS compiler to allow unqualified references to properties of the window object that are declared in an extension to the Window interface? For example:
// accepted, because has type string

// rejected, because the Window interface doesn't have an "x" property
// and no local variable called "x" has been declared

interface Window {
    foo: number;

// accepted = 4;

// rejected: "could not find symbol 'foo'"
Intuitively, I would expect that adding a property onto the Window interface would make that property accessible globally (without explicitly referring to it as a property of the window object) - that seems to be how the built-in Window interface behaves, and it would mirror the runtime behavior of the window object. Is there any way to get the typechecker to accept that without having to declare each property twice (once in the extended Window interface and once in a "declare var" statement)?
Jun 25, 2014 at 7:19 PM
Oh, upon further investigation it seems that lib.d.ts actually does declare all of the Window properties twice, so I guess I have my answer there.