TS7022

error TS7022: ‘window‘ implicitly has type ‘any‘ because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Broken Code ❌

1
var window = window || null;
tsconfig.json
1
2
3
4
{
"compilerOptions": {
"lib": ["es2017"]
}

Fixed Code ✔️

The above error can occur when TypeScript doesn’t know about the window interface. Make sure to add “dom” to your list of known runtime libraries in your compiler options:

tsconfig.json
1
2
3
4
{
"compilerOptions": {
"lib": ["dom", "es2017"]
}