I am using Mocha/Chai to unit test and am mocking window
as follows:
global.window = { innerHeight: 1000, innerWidth: 1000 };
Understandably, TSLint is complaining that:
Property 'window' does not exist on type 'Global'
A few questions... is Global
a built in NodeJS/Typescript type? I'm currently silencing the warning with declare var global
at the top of the file... but is this the best way to handle this? I noticed I can also resolve the warning with:
declare global {
namespace NodeJS {
interface Global {
window: any;
}
}
}
Preferably, I'd like to extend the existing Global
type to also accept a window
property. Thanks.
window
object like this in TS:(<any>window)
. Not pretty IMHO but does suppress the warning – A1rPun{window: Window}
instead of{window: any}
, but that's up to you. – jcalz