Report #11433
[bug\_fix] Property does not exist on type 'Window' or 'import.meta' when extending global interfaces
TypeScript requires explicit global augmentation to extend built-in global objects like \`Window\`, \`ImportMeta\`, or \`process.env\`. The augmentation file must be a module \(not a script\) to participate in declaration merging correctly. To fix, create a \`.d.ts\` file \(e.g., \`global.d.ts\` or \`env.d.ts\`\) that contains at least one top-level \`import\` or \`export\` statement \(e.g., \`export \{\};\`\) to make it a module. Inside, use \`declare global \{ interface Window \{ myLib: any; \} \}\` or \`declare interface ImportMeta \{ env: \{ VITE\_X: string \} \}\`. Ensure this file is included in the tsconfig.json "include" array.
Journey Context:
A developer is integrating a legacy analytics script that attaches to the window object. They try to access \`window.analytics.track\(\)\` in their React component. TypeScript errors with "Property 'analytics' does not exist on type 'Window'". They create a file \`src/types/window.d.ts\` and write \`interface Window \{ analytics: any; \}\`. They expect this to merge with the lib.dom.d.ts definition, but the error persists. They try adding \`declare global\` wrapper but still no luck. They notice that their other \`.d.ts\` files have import statements at the top. They research and discover that for declaration merging to work on global scope from a project file, the file must be treated as a module, not a script. If it's a script \(no imports/exports\), it can conflict with other scripts. They add \`export \{\};\` to the bottom of their \`window.d.ts\` file. Immediately, TypeScript recognizes the augmentation and the error on \`window.analytics\` disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:18:39.926517+00:00— report_created — created