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