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

4
  • for window i usually just make it an any instead of trying to extend it. (<any>window).appConfig = (<any>window).appConfig || {}; Here is a possible duplicate stackoverflow.com/questions/12709074/… Commented Nov 3, 2015 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 Commented Nov 3, 2015 at 16:55
  • have you tried doing the import above the interface? maybe lodash is overwriting or creating their own interface for window? Commented Nov 3, 2015 at 16:57
  • Yes. You can see it in the typescript playground Commented Nov 3, 2015 at 16:58

1 Answer 1

4

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.