In this post, we will learn how to fix “Property does not exist on type Window” error in TypeScript. Now, let’s follow some steps. I will show you how to do it.
Why does the “Property does not exist on type Window” error in TypeScript happen?
The “Property does not exist on type Window” error in TypeScript occurs when we get admission to a property that no longer exists in the “Window” interface.
For example, when the error occurs:
window.test = 'hello'; console.log(window.test);
Output:
Property 'test' does not exist on type 'Window & typeof globalThis'.ts(2339).
How can we fix this error?
To fix the “Property does not exist on type Window” error in TypeScript. We need to extend the “Window” interface and add the property you intend to get admission to on the ‘window’ object.
Let’s follow three steps below to know how to fix it:
Step 1: Create a file, set the ‘index.d.ts’ name somewhere in your project, and define the type on the “Window” object
For example:
export {}; declare global { interface Window { // Some properties... } }
Make certain that you truly declare a global variable on the “Window” object. In many cases, this can be changed regarding a variable in a module and while it truly is no longer a black-and-white issue. Heading off global variables is regarded as a satisfactory practice in JavaScript.
If the folder already has the file name “index.d.ts”, maybe you can change this name to “global.d.ts” or any name you want.
Step 2: Add some property you will use in your project
For example:
index.d.ts
export {}; declare global { interface Window { someProperty: any; address: string; time: number; // etc... } }
You can define different properties in other ways.
For instance, below the code:
index.d.ts
export {}; declare global { interface Window { example: any; gtag: (...args: any[]) => void; } }
In this program, I added an “example” global variable object as ‘any’ type, but “example” doesn’t provide TypeScript options for its widget, so we are not sure what “example” contains.
Step 3: (Optional) Add a reference in the tsconfig.json file
Finally, we can add a reference to make sure “typeRoots” probably works. Follow this code below:
{ "compilerOptions": { "typeRoots": [ "./src/types", "./types" ] } }
If you using Node.js, let’s follow this way:
tsconfig.json
{ "compilerOptions": { "typeRoots": [ "./node_modules/@types", "./src/types" ] } }
Summary
The “Property does not exist on type Window” error in TypeScript occurs when we get admission to a property which no longer exists in the “Window” interface. After reading the post, I hope you will learn how to fix this error. I hope this tutorial is helpful to you. Happy coding.
Maybe you are interested:
- ReferenceError: exports is not defined in TypeScript
- Property does not exist on type ‘never’ in TypeScript
- Property ‘value’ does not exist on type ‘HTMLElement’ in TS

Hello, my name is Philip Cabrera. My job is a programmer, and I have 4 years of programming expertise. Follow me if you need assistance with C, C++, JS, TS, or Node.js. I hope my posts are useful to you.
Name of the university: HUMG
Major: IT
Programming Languages: C, C++, JS, TS, Node.js