How to use TypeScript with restProps in Svelte 5 without errors? #10536
Closed
unikitty37
started this conversation in
General
Replies: 2 comments 3 replies
-
Try something like: type ButtonProps = {
theme?: 'primary' | 'secondary',
children: Snippet, // from `'svelte'`
[key: string]: any, // for all other properties
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
Any reasons not to do this? You even get IntelliSense this way. let {
theme,
...rest,
}: {
theme?: 'primary' | 'secondary';
} & HTMLButtonAttributes = $props(); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
$$restProps
is deprecated in Svelte 5, and the documentation gives this as the alternative:but unfortunately doesn't include the definition of the MyProps type. I have this:
but when I invoke the component like this:
I get the error "Object literal may only specify known properties, and 'children' does not exist in type 'ButtonProps'. ts(2353)". The component still works as expected, but I'd like to have a CI process that rejects commits that generate TypeScript errors :)
What should I be putting here?
Beta Was this translation helpful? Give feedback.
All reactions