Skip to content

example of state merging in reducer not compliant with TS v2.4 #4

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

Closed
khell opened this issue Jun 22, 2017 · 5 comments
Closed

example of state merging in reducer not compliant with TS v2.4 #4

khell opened this issue Jun 22, 2017 · 5 comments
Assignees

Comments

@khell
Copy link

khell commented Jun 22, 2017

Hi,

Thank you for the guide.

How would you recommend the example on "Spread operation with Exact Types check to guard against excess or mismatched props" be used with strictNullChecks? As a Partial makes all properties nullable, it is required to define all State in this form:

export type State = {
  readonly counter: number | undefined,
  readonly baseCurrency: string | undefined,
};

This is the same as effectively switching strictNullChecks off. Is there any other way?

Cheers.

@piotrwitek
Copy link
Owner

piotrwitek commented Jun 22, 2017

Hi @khell,
I'm curious why you think that it is required to define all State props in nullable form?
Is it something in the guide misleading you?

Have you checked the playground link to play with it yourself (the goodReducer example)?
Note: There is option to enable strictNullChecks in playground.
The solution works with TS 2.3 and you can guard against mismatched props.

It will probably break in next release v2.4 because they changed how spread is typed, but I'm working on that and will update the guide accordingly.

@khell
Copy link
Author

khell commented Jun 23, 2017

Ah, I was using Typescript 2.4 somehow and ran into microsoft/TypeScript#16509. Thanks for the assistance.

@piotrwitek
Copy link
Owner

@khell no problem, it's good that you have pointed out an issue as this is something that need to be revised and handled for v2.4
I'll keep it open for tracking

@piotrwitek piotrwitek self-assigned this Jun 23, 2017
@piotrwitek piotrwitek changed the title Usage with strictNullChecks: true example of state merging in reducer not compliant with TS v2.4 Jun 23, 2017
@piotrwitek
Copy link
Owner

the related issue is fixed microsoft/TypeScript#16509

@piotrwitek
Copy link
Owner

piotrwitek commented Aug 28, 2017

also the guide was updated to reflect the changes and the problem does not exist anymore :)
please check: https://github.com/piotrwitek/react-redux-typescript-guide/blob/8ccf66955d42d03151cc1e53b58af5eff2b0a237/README.md#reducer-with-classic-const-types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants