Skip to content
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

TS Types for Svelte 5 $state reactivity #11546

Closed
saturnonearth opened this issue May 10, 2024 · 3 comments
Closed

TS Types for Svelte 5 $state reactivity #11546

saturnonearth opened this issue May 10, 2024 · 3 comments

Comments

@saturnonearth
Copy link

Describe the problem

At the moment, it is difficult to tell whether a variable that you are returning is reactive or not, as when you hover over the variable, it just shows the primitive value such as boolean. In Svelte 4, it didn't really matter because everything was reactive, but now, it needs to be more explicit (from my understanding).

Describe the proposed solution

It would be nice if when hovering over a state enabled variable that Typescript could point this out, such as SvelteState<string>.

Importance

would make my life easier

@Conduitry
Copy link
Member

I doubt this is practical. We'd also need to worry about how the types of SvelteState<some_type> interact with everything else. I don't know that we can tell TypeScript 'SvelteState<some_type> behaves basically like some_type, but don't just drop the SvelteState<> part.

@brunnerh
Copy link
Member

brunnerh commented May 10, 2024

A boolean returned from a function will never be reactive since it's a primitive which is passed by value.

Encoding this in the types will not work anyway, though, since that is a separate thing. If you assign a state variable to a new constant, the type would transfer but the reactivity would be lost for primitives.

@trueadm
Copy link
Contributor

trueadm commented May 10, 2024

This just isn't possible, sorry.

@trueadm trueadm closed this as completed May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants