Skip to content
Discussion options

You must be logged in to vote

What if the fields in initialState are null, undefined, union types, or string? We can use TypeScript’s as syntax to fix this issue and avoid rewriting the store’s type. For example:

const initialState = {
  bears: 0,
  gender: 1 as 0 | 1 | 2 | undefined,
};
export type BearState = typeof initialState;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by suhaotian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
1 participant