sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
79.77k stars 4.23k forks source link

Svelte 5: Document extending types from svelte/elements when setting up props interface #13006

Closed felix-tjernberg closed 2 weeks ago

felix-tjernberg commented 2 months ago

Describe the problem

Could not find in the docs what type I should when typing the props interface when building for example a button for our projects component library

Describe the proposed solution

As an inexperienced typescript developer you should be guided in the docs to use types from svelte/elements module, so you don't fall into the trap of typing out all attributes yourself

A simple example would be something like this

Button.svelte

<script lang="ts">
    import { type HTMLButtonAttributes } from "svelte/elements"
    interface props extends HTMLButtonAttributes {
         /* place your stuff here */
    }
    let { ...restProps }: props = $props()
</script>
<button {...restProps}></button>

A community member suggested to add svelte-elements.md in https://github.com/sveltejs/svelte/tree/main/documentation/docs/98-reference

Importance

would make my life easier

rChaoz commented 2 months ago

I believe this is documented here, but it would be very useful to mention it with a link in the props section.