How can I declare ("typescript": "3.x.x" ) that inside window object, I have some variable with some type?
E.g. I have window.foo = { bar: 'baz' }
, how can I declare it? Old way of doing that was:
declare global {
interface Window {
foo: { bar: string }
}
}
And it produces this error
TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.
It looks like just adding a record in some d.ts file is ok. Like this:
interface Window {
foo: { bar: string }
}
But as I understood in such case I can't import some types in that file and use them in declaration, instead of string
for example.
So what if I want to do something like that:
import { MyTypeFromSomewhere } from './somewhere'
interface Window {
foo: { bar: MyTypeFromSomewhere }
}
How can I extended Window interface with new property and specify type for it?