0

What I'm Trying to Do...

I'm attempting to extend the Window interface using TypeScript but also want to follow the recommended TSLint rules.

What Searches Have Produced/Suggested...

Other StackOverflow questions such as How do you explicitly set a new property on window in TypeScript? largely recommend extending the Window interface which seems like a preferred solution to using (window as any) everywhere you reference Window.

The Issue I'm Facing...

When using what seems like the ideal solution...

declare global {
    interface Window {
        MY_GLOBAL_VAR1: string; // reference with window.MY_GLOBAL_VAR1
        MY_GLOBAL_VAR2: bool; // reference with window.MY_GLOBAL_VAR2
    }
}

... the recommended TSLint throws an error because of the "no-namespace" rule.

The Plea For Help...

My goal is to not override this rule if possible. Has anyone found a solution to satisfy extending Window in a recommended TSLint-compatible way?

Ronan M
  • 65
  • 4
  • What version of TSLint are you using? This looks like a fixed bug: https://github.com/palantir/tslint/issues/1833 – Daniel Rosenwasser Jun 07 '17 at 16:22
  • I'm using 5.4.2 but see there's a 5.4.3. I updated and it's the same because I'm not utilizing the "allow-declarations" since that's not part of the recommended tslint. The recommendation is still `"no-namespace": true`, – Ronan M Jun 08 '17 at 01:47

0 Answers0