Report #78435
[bug\_fix] Property 'dataLayer' does not exist on type 'Window & typeof globalThis'.
Create a type declaration file \(e.g., 'global.d.ts'\) containing 'export \{\}; declare global \{ interface Window \{ dataLayer: any\[\]; \} \}'. This uses declaration merging to augment the global Window interface in the module context.
Journey Context:
Developer is integrating Google Tag Manager into a React app. They write 'window.dataLayer.push\(\{ event: 'pageview' \}\)'. TypeScript immediately flags 'dataLayer' with 'Property does not exist'. The developer tries casting: '\(window as any\).dataLayer'. This silences the error but feels wrong. They search for 'typescript extend window object'. They find suggestions to use 'declare global'. They create a file 'types/window.d.ts' and write 'interface Window \{ dataLayer: any\[\]; \}'. It doesn't work; the error persists. They realize their file is treated as a module \(has imports/exports\), so the interface declaration is local. They need 'declare global' wrapper. They change it to 'declare global \{ interface Window \{ dataLayer: any\[\]; \} \}'. Still errors. They add 'export \{\};' at the top to ensure it's a module, then 'declare global' works. The augmentation is applied globally, and 'window.dataLayer' type-checks correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:15:00.019311+00:00— report_created — created