-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Svelte 5: $props()
isn't generic anymore
#10812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is intentional, see #10694 |
@trueadm thanks. This issue applies to |
@Aloso let counter: number = $state(0); |
Still looks generic: svelte/packages/svelte/src/main/ambient.d.ts Lines 17 to 18 in 474fc7e
|
Sorry, I meant that it's never needed to be based a discrete generic. The inference system should play ball with the type annotation on the declaration – which is important as the initial value needs to align, thus generic is needed. |
The generic is often required. For example: let s = $state<'idle' | 'loading' | 'done'>('idle') |
Why can't you do? let s: 'idle' | 'loading' | 'done' = $state('idle') |
@trueadm of course this works, but the function still needs to be generic. If you made it function $state(initial: any): any Then it wouldn't be type-safe. |
@Aloso We are not going to make it |
|
Describe the bug
After updating to
5.0.0-next.79
, I got type errors in all my components:Instead, I need to write this:
Note that other runes, such as
$state()
, still support generics.Reproduction
See above (the error appears in VS Code, but not in the web editor)
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: