3

I used stackoverflow How do you explicitly set a new property on `window` in TypeScript? to extend window. The code looks like the following:

interface Window { appConfig: any; }
window.appConfig = window.appConfig || {};

Everything works fine.

When i add the line

import _ = require('lodash');

I get an error

Error TS2339: Property 'appConfig' does not exist on type 'Window'.

How can i fix this issue?

I work with typescript 1.6.2

Community
  • 1
  • 1
David Michael Gang
  • 7,107
  • 8
  • 53
  • 98
  • for window i usually just make it an any instead of trying to extend it. `(window).appConfig = (window).appConfig || {};` Here is a possible duplicate http://stackoverflow.com/questions/12709074/how-do-you-explicitly-set-a-new-property-on-window-in-typescript – Tony Nov 03 '15 at 16:53
  • this is not a duplicate. I am not asking about how to extend window. I am asking about why the import statement brings the error – David Michael Gang Nov 03 '15 at 16:55
  • have you tried doing the import above the interface? maybe lodash is overwriting or creating their own interface for window? – Tony Nov 03 '15 at 16:57
  • Yes. You can see it in the typescript playground – David Michael Gang Nov 03 '15 at 16:58

1 Answers1

3

When using external modules, interfaces found in .ts files won't be merged with interfaces found in .d.ts files. So in this case, it's not working because the Window interface in the .ts file isn't merged with the Window interface found in lib.d.ts. That's due to the nature of external modules.

To fix it, move...

interface Window { appConfig: any; }

...into a definition file (.d.ts).

David Sherret
  • 101,669
  • 28
  • 188
  • 178