You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A follow-up to #13770 which identified using Component<typeof MyComponent> and ComponentProps<typeof MyComponent>, this requests that an example is added to web docs typescript#The-Component-type.
Describe the proposed solution
A typical use case is when using wrapper components (for ComponentProps). It may be too much revision, but it ties along nicely with Typing wrapper components two sections above, and may fare well to move that section below Typing $state. That said I understand that $state typing is introduced so late on page as it requires generics and so do Component and ComponentProps. So a rough idea is after withProps(), add
Use typeof MyComponent for the type of your component.
<scriptlang="ts">importtype{ComponentProps,Snippet}from'svelte';importBannerfrom'./Banner.svelte';
let { name ='Bruce', children, ...bannerProps} : {name?: string,children?: Snippet}&ComponentProps<typeofBanner>=$props()</script><p>{name}</p><Banner{...bannerProps}>
{@render children?.()} // Banner.svelte needs to accept snippets or legacy slots for this to work.
</Banner>
It's just a rough idea, feel free to totally change it.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered:
I totally agree about ComponentProps<typeof MyComponent>.
About Component<...>, I wonder how documentation of Component type directly helps normal developers (I think adding an example of Component makes sense but it's at least an advanced topic).
IMHO, documenting / adding examples of an instance/exports of the component (ReturnType<typeof MyComponent>) might be important just as ComponentProps (for instance, bind:this target to a Svelte 5 component (with some exports) will require this type).
Note: if #13441 is accepted, ComponentExports<typeof MyComponent> will be more natural.
Describe the problem
A follow-up to #13770 which identified using
Component<typeof MyComponent>
andComponentProps<typeof MyComponent>
, this requests that an example is added to web docs typescript#The-Component-type.Describe the proposed solution
A typical use case is when using wrapper components (for ComponentProps). It may be too much revision, but it ties along nicely with Typing wrapper components two sections above, and may fare well to move that section below Typing $state. That said I understand that $state typing is introduced so late on page as it requires generics and so do Component and ComponentProps. So a rough idea is after
withProps()
, addUse
typeof MyComponent
for the type of your component.It's just a rough idea, feel free to totally change it.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: