Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript does not know the property you added to window

ErrorProperty 'myAppConfig' does not exist on type 'Window & typeof globalThis'.

Short answer

TypeScript only knows the properties of Window it was given. A value added by a script tag, an SDK or your own code is unknown to it. Declare it once by merging into the Window interface inside declare global, in a file that is a module, and make sure tsconfig includes the file.

  • Applies to TypeScript 5.5, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find where the property is read and whether any declaration file mentions Window already.

    grep -rn "interface Window\|declare global" src/ *.d.ts
  2. 2Match what you see, then jump to its fix

    1. 1TS2339 naming Window or Window & typeof globalThisThe property was never declared on WindowFix
    2. 2You added the declaration and the error did not go awayThe declaration exists but tsconfig does not include itFix

What does the error look like?

  • Property 'myAppConfig' does not exist on type 'Window & typeof globalThis'.
  • Property 'dataLayer' does not exist on type 'Window'.

Cause 1 of 2

The property was never declared on Window

1Check

Interfaces with the same name merge their members into one interface, and global augmentation adds declarations to the global scope from inside a module.

grep -rn "window\.myAppConfig" src/

2Fix

Add a declaration file that augments the global Window interface. The export {} line makes the file a module, which declare global requires.

// src/global.d.ts
export {};

declare global {
  interface Window {
    myAppConfig: { apiUrl: string };
  }
}

3Verify

Type-check the project.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

Cause 2 of 2

The declaration exists but tsconfig does not include it

1Check

A declaration only applies when the compiler reads the file. Check which files tsconfig includes.

npx tsc --listFilesOnly | grep global.d.ts

2Fix

Put the file under a folder listed in include, or add it explicitly, then restart the editor's TypeScript server.

{
  "include": ["src", "src/global.d.ts"]
}

3Verify

The file now shows in the listing and the error is gone.

npx tsc --listFilesOnly | grep global.d.ts && npx tsc --noEmit

Confirmed by vite.dev

Did this fix it?

How do I stop it coming back?

  • Keep all global augmentations in one global.d.ts file.
  • Declare the property as optional (?) if it may not exist at runtime.
  • Do not cast window to any; the declaration documents what exists.
  • Declare only what you use, and check for it at runtime when a script may fail to load.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

TypeScript rejects MUI Data Grid columns that set a type

A TypeScript error inside a column's renderCell callback

A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.