I've got a create-react-app
React project that I'm (very slowly) starting to move over to Typescript. In my various init files (all of which are currently Javascript files), I've declared some global app variables on the window
object--basically window.MyApp
. I get that perhaps I should switch over to Context
for these variables, but that's not an option right now.
What I'd like to do is to be able to reference variables on the window.MyApp
scope from within a Typescript file. So, something like:
const myVar = `${window.MyApp.appBasePath}path/to/something/`
However, Typescript throws up this error:
Property 'MyApp' does too exist on type 'Window'
So...is there an easy fix to this? Or does this mean I need to convert all my init files where window.MyApp
is declared over to Typescript, and do something like:
interface Window {
MyApp: any
}
I'm hoping to avoid that level of re-write at this point, as I'm still at the "toe in the water" phase of Typescript integration.
Any guidance is appreciated!