-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Error when compiling with option "strict: true" (nightly build) #33
Comments
Still seeing this in the latest nightly. |
This is due to the parameter destructuring, and I've fixed it with the following: export type StateActionPair<T, V extends Action = Action> = { state: T | undefined, action?: V };
export function reduceState<T, V extends Action = Action>(
stateActionPair: StateActionPair<T, V> = { state: undefined },
[ action, reducer ]: [ V, ActionReducer<T, V> ]
): StateActionPair<T, V> {
const { state } = stateActionPair;
return { state: reducer(state, action), action };
} It's caused by the fact that the parameter is possibly undefined (because there's a default assignment), and therefore the destructuring isn't safe as the type definition is An alternative approach is to remove the default assignment (which I think probably makes more sense): export type StateActionPair<T, V extends Action = Action> = { state: T | undefined, action?: V };
export function reduceState<T, V extends Action = Action>(
{ state }: StateActionPair<T, V>,
[ action, reducer ]: [ V, ActionReducer<T, V> ]
): StateActionPair<T, V> {
return { state: reducer(state, action), action };
} Sorry I can't submit a PR. Corporate firewalls! |
When I add the option
"strictNullChecks": false
, the error goes away.The text was updated successfully, but these errors were encountered: