language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Error: Object literal may only specify known properties, and '"..."' does not exist in type 'SvelteWindowAttributes'. (ts)

Open peterpeterparker opened this issue 4 months ago • 2 comments

Describe the bug

When I upgrade Svelte to latest (v5.36.0 -> 5.38.1), I get following kind of errors reported when I run npm run check:

/Users/david...nts/loaders/CanistersStatusLoader.svelte:58:16
Error: Object literal may only specify known properties, and '"onjunoRestartCycles"' does not exist in type 'SvelteWindowAttributes'. (ts)

<svelte:window onjunoRestartCycles={restartCycles} />


/Users/daviddalbusc...onents/modals/Modals.svelte:38:16
Error: Object literal may only specify known properties, and '"onjunoModal"' does not exist in type 'SvelteWindowAttributes'. (ts)

<svelte:window onjunoModal={({ detail }) => (modal = detail)} />

Reproduction

My configuration in app.d.ts:

declare namespace svelteHTML {
	interface HTMLAttributes<T> {
		onjunoIntersecting?: (event: CustomEvent<any>) => void;
		onjunoModal?: (event: CustomEvent<any>) => void;
		onjunoSyncCustomDomains?: (event: CustomEvent<any>) => void;
		onjunoRestartCycles?: (event: CustomEvent<any>) => void;
		onjunoReloadVersions?: (event: CustomEvent<any>) => void;
		onjunoCloseActions?: (event: CustomEvent<any>) => void;
		onjunoRegistrationState?: (event: CustomEvent<any>) => void;
		onjunoReloadAuthConfig?: (event: CustomEvent<any>) => void;
		onjunoRestartWallet?: (event: CustomEvent<any>) => void;
	}
}

Seems to follow what's described in the documentation:

declare namespace svelteHTML {
    // enhance elements
    interface IntrinsicElements {
        'my-custom-element': { someattribute: string; 'on:event': (e: CustomEvent<any>) => void };
    }
    // enhance attributes
    interface HTMLAttributes<T> {
        // If you want to use on:beforeinstallprompt
        'on:beforeinstallprompt'?: (event: any) => any;
        // If you want to use myCustomAttribute={..} (note: all lowercase)
        mycustomattribute?: any;
        // You can replace any with something more specific if you like
    }
}

Note that I tried to declare both onSomething and on:something but, it did not resolved the issue.

Expected behaviour

No types issue.

System Info

Irrelevant.

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

No response

peterpeterparker avatar Aug 14 '25 15:08 peterpeterparker

We need to udpate / remove that outdated documentation, you should do it this way from now on: https://svelte.dev/docs/svelte/typescript#Enhancing-built-in-DOM-types (will mean the types are also enhanced with your new attributes when you import the interfaces for example, not just when using it in the template)

Still this is a regression so I'll try to look into it. Not sure what could've caused it though.

dummdidumm avatar Aug 14 '25 15:08 dummdidumm

Thanks! Migrating (PR) the declaration to a svelte/elements resolves the issue.

peterpeterparker avatar Aug 15 '25 05:08 peterpeterparker