Report #47264
[bug\_fix] Property 'myCustomProp' does not exist on type 'Window' \(TS2339\) despite declaring global.d.ts augmentation
Ensure the augmentation file is either: \(1\) a script file with no top-level 'import' or 'export' keywords, or \(2\) if it must contain imports/exports, wrap the Window extension in 'declare global \{ ... \}'. Additionally, verify the file is included in the TypeScript project via the 'include' array in tsconfig.json \(e.g., 'include': \['src', 'types/\*\*/\*.d.ts'\]\) and is not excluded by 'exclude'
Journey Context:
Developer needs to access a third-party library attached to the browser window object: 'window.thirdPartyLib'. TypeScript complains that 'thirdPartyLib' doesn't exist on type 'Window'. They create 'src/types/global.d.ts' with content: 'interface Window \{ thirdPartyLib: any; \}'. They reload the IDE, but the error persists. They check tsconfig.json and see 'include': \['src/\*\*/\*'\], which should cover the file. They realize the file has 'export \{\};' at the bottom from a previous edit—this makes it a module rather than a script, scoping the interface declaration to the module rather than augmenting the global Window. They remove the export, but still see the error in some files. They realize that files containing 'import' statements also become modules. Since their global.d.ts imports another type for the lib's types \('import type \{ LibType \} from './libTypes''\), it must explicitly use 'declare global'. They wrap the interface: 'declare global \{ interface Window \{ thirdPartyLib: LibType; \} \} export \{\}'. Now the augmentation applies globally, and the error disappears across all files.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:48:41.535880+00:00— report_created — created