better way to type props with default props
this is what i've come up with so far. is there a simpler/better way to type it?
- the props should be optional, since i'm defining defaults for it
- it should include optional children, since that's a special prop
- i don't want a separate prop type for each component.
- it should account for the fact that there can be additional props (thus the record string extension) - is this not a good idea? let me know!
this works but, maybe i'm missing some obvious way to do it better.
if this is really the general way it should be typed (like solid does not have some helper types for the pretty common scenario of default props), atleast i'd like to get rid of the
typeof
if possible, and move that to the helper type.5 Replies
here's my playground link
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
having to type default props this awkwardly feels like several steps backward coming from svelte, but there's enough of an IKEA effect (i built it myself, so it must be good) where i could imagine using this.
Solid provides the
ParentComponent
type when you want to specify that the component accepts children. I believe this only works with arrow functions
However, you can also use the ParentProps
type for regular function
declarations
okay, i'll test that and update with my experience here
thanks so far
okay, i'm pretty happy with
thanks!
i feel like this is a pretty common pattern, and could be documented somewhere / shown in the tutorial.