I have the following working (running) code but am getting the TypeScript error Property 'onSubmit' does not exist on type 'Window & typeof globalThis'..
function onSubmit() {
. . .
}
onMount(() => {
window.onSubmit = onSubmit; <-- Error
});
onDestroy(() => {
window.onSubmit = null; <-- Error
});
In my global.d.ts file I have tried exporting an interface to import
export interface CustomWindow extends Window {
onSubmit: () => void;
}
and declaring a global
declare global {
interface Window {
onSubmit: () => void;
}
}
Neither solution has been successful, the error persists. How can we add properties to the window object for TypeScript to recognize?