Inferred Zustand types...

Hi, New to Zustand. The typescript guide says you can infer types with combine but this makes it tricky to do nested state. I found that simply doing
type State = ReturnType<typeof state>
export const useStore = create<State>()(state)
type State = ReturnType<typeof state>
export const useStore = create<State>()(state)
seems to work, but this seems too easy. All the examples have the state explicitly created, not inferred. Am I missing something obvious?
4 Replies
benten
bentenOP3y ago
Like I'm guessing a limitation is that the type is only what is inferred, so that might limit you But that limitation exists when inferring state as well with combine or even something like this
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
benten
bentenOP3y ago
Is there a reason I can't just infer my state like this? I know there is combine, the Zustand docs talk about how it's not possible to infer state otherwise because state generic T is invariant. But this seems to work, so...
benten
bentenOP3y ago
Want results from more Discord servers?
Add your server