1

I have a js file in my src folder.

export default class UserAuth {
...
}

In my index.tsx file I want to set a new property on window.

window.UserAuth = new UserAuth();

With this, Iam getting the following error: Property 'UserAuth' does not exist on type 'Window'.

I tried adding the following code in lib.dom.d.ts but the error still exists

interface Window {
   UserAuth: any;
}
thewebtud
  • 455
  • 2
  • 4
  • 21

1 Answers1

0

You can cast window to any and use it dynamically like:

const win = (<any>window);
win.UserAuth = new UserAuth();
console.log(win.UserAuth);
palaѕн
  • 72,112
  • 17
  • 116
  • 136