Skip to content

Only allow returning known fields/properties when using set (v4, TypeScript) #1318

Closed Answered by devanshj
bennettdams asked this question in Q&A
Discussion options

You must be logged in to vote

I know that TypeScript is not doing exact type checks out of the box, but this can be implemented with helper types. Was just wondering if this is implemented already for Zustand or if my usage of the set function etc. is wrong.
And also, TypeScript v4.9 brings the satisfies operator, which makes this even easier.

Your usage is correct, it's just that zustand doesn't and hasn't considered involving in hacks to get around TypeScript's structural types. It's true that exact types would be useful here (as you said to catch typos etc) but the issue is better handled on TypeScript's end (microsoft/TypeScript#12936) so that we get good errors etc.

Nevertheless you can still implement them in …

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@bennettdams
Comment options

@bennettdams
Comment options

Comment options

You must be logged in to vote
2 replies
@bennettdams
Comment options

@devanshj
Comment options

Answer selected by bennettdams
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants