Closed rChaoz closed 5 days ago
This already exists, just import what you need from svelte/elements
@dummdidumm I did not know that. Could this potentially be re-opened and tagged as documentation? I could not find info about this anywhere, neither on the official nor the preview site.
svelte/elements
Yea using the search on the site for svelte/elements
doesn't really filter to it adequately; even doing this in google search site:svelte.dev 'svelte/elements'
turns up nothing useful and that's knowing what to look for. I only found out about it from the Discord, but a vague example is buried on this page: https://svelte.dev/docs/typescript#enhancing-built-in-dom-types
Yep, that's exactly what I did. That page says that the types may be incomplete, but doesn't actually state what exactly those types are or how to use them, and doesn't mention the keywords "svelte/elements" to be easily findable either.
If I want to make a PR for this - where should I add the documentation? There are a two places I can think of:
The best place would be within the MISC / Typescript
section for now. Mid term we have to rethink the docs structure, but that's a separate process which hasn't started yet.
Initially I tried starting to write where you said but then I realized there's an issue: there's no way to type rest props in Svelte 4. The only way to do it would be using the $$Props
interface, which is intentionally left out from the documentation (and instead a link to the RFC is provided). And even then, you'd have to write the types twice:
interface $$Props extends HTMLDivProps {
myProp1: number
myProp2: string
}
export let myProp1: number
export let myProp2: string
I don't think adding this to the docs would be a great idea. How about a new entry on the Svelte 5 preview site, under imports, for now? And it would make more sense when the docs will eventually be unified together.
Describe the problem
In Svelte 5, it is easier than ever to type props and forward them to an element:
This is great, especially that it now works with listeners as well. However, there isn't really a way to get type assistance for the extra props (for the
button
element, in this case).Describe the proposed solution
Built-in type classes for this case, so we could have something like
Importance
would make my life easier