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

Error when compiling with option "strict: true" (nightly build) #33

Closed
mxth opened this issue May 31, 2017 · 2 comments
Closed

Error when compiling with option "strict: true" (nightly build) #33

mxth opened this issue May 31, 2017 · 2 comments

Comments

@mxth
Copy link

mxth commented May 31, 2017

node_modules/@ngrx/store/src/state.d.ts (20,68): Type 'StateActionPair<T, V> | undefined' has no property 'state' and no string index signature.

When I add the option "strictNullChecks": false, the error goes away.

@jinder
Copy link
Contributor

jinder commented Jun 22, 2017

Still seeing this in the latest nightly.

@jinder
Copy link
Contributor

jinder commented Jun 22, 2017

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 StateActionPair<T, V> | undefined.

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!

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

2 participants