Report #49147
[bug\_fix] Property 'electronAPI' does not exist on type 'Window & typeof globalThis'.
Use declaration merging to augment the global \`Window\` interface. Create a \`global.d.ts\` file \(or any \`.d.ts\` file\) containing \`declare global \{ interface Window \{ electronAPI: \{ send: \(channel: string\) => void; \}; \} \} export \{\};\`. The empty export ensures the file is a module, allowing \`declare global\` to work. This merges the new property into the existing DOM \`Window\` interface.
Journey Context:
Developer is building an Electron app. In the preload script, they expose an API via \`contextBridge.exposeInMainWorld\('electronAPI', \{ send: ... \}\)\`. In the renderer's TypeScript code, they write \`window.electronAPI.send\('ping'\)\`. TypeScript complains that \`electronAPI\` does not exist on \`Window\`. They try casting \`\(window as any\).electronAPI\`, which works but loses type safety. They search "typescript extend window interface" and find answers mentioning \`declare global\`. They create \`src/global.d.ts\` and write the augmentation. At first, it doesn't work because they forgot the \`export \{\}\` to make it a module, or they placed it inside a script file instead of a global \`.d.ts\`. After correcting it, the error disappears and they get full autocomplete for \`electronAPI\`. This works because TypeScript merges interface declarations in the same global scope.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:58:25.128453+00:00— report_created — created