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

Consider removing the `Omit` type from the `HTMLProps` type

Open dummdidumm opened this issue 1 year ago • 2 comments

This type in our d.ts file in svelte2tsx:

type HTMLProps<Property extends string, Override> =
    Omit<import('svelte/elements').SvelteHTMLElements[Property], keyof Override> & Override;

Results in the data-${string} type overriding any more narrow types like data-sveltekit-... In other words, I can pass an invalid value to data-sveltekit-.. and it doesn't error, because the fallback type overrides it so that anything is allowed.

The question now is: Should we simplify the HTMLProps type to import('svelte/elements').SvelteHTMLElements[Property] & Override? The one drawback is that you cannot pass properties that have conflicting types anymore. Given that you rarely want to override a type (you mainly want to add new ones), and in case you do want to override them, you mostly want to narrow them (which is fine with the simplified type, too), I lean towards making this change. @jasonlyu123 thoughts?

dummdidumm avatar Dec 07 '23 14:12 dummdidumm

Another possibility is that some event type was changed to a new sub-type, and people want to enhance it. Like the submit event situation in https://github.com/sveltejs/language-tools/issues/1305. There is also another problem. We have the same HTMLProps in the Svelte 4 version of svelteHTML, so it might be considered a breaking change.

jasonlyu123 avatar Dec 08 '23 05:12 jasonlyu123

Another possibility is that some event type was changed to a new sub-type, and people want to enhance it

Do you mean this as in "this is another use case where people want the current behavior, and it would no longer possible if we changed the type"?

We have the same HTMLProps in the Svelte 4 version of svelteHTML, so it might be considered a breaking change.

Good point, if we do it then probably as part of Svelte 5 typings

dummdidumm avatar Dec 08 '23 07:12 dummdidumm