Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

AddReducer type inference #105

Closed
MikeMeyers2504 opened this issue Jul 8, 2019 · 2 comments
Closed

AddReducer type inference #105

MikeMeyers2504 opened this issue Jul 8, 2019 · 2 comments
Assignees
Labels
feature A new feature is requested.
Milestone

Comments

@MikeMeyers2504
Copy link

MikeMeyers2504 commented Jul 8, 2019

image

image

Hey, I love reactn by the way :)
I have recently updated reactn from 1 to 2 in my application.
But I have a question with type inference.
I added a global.d.ts file in my root folder and there I declared the type for the State and Reducers.
If I use it like this the type inference is good.

image

But in the addReducer function (1ste pic) the item, type, and FilterKey are of type any. Why do these don't have the types through inference? Do I need to type them seperately?

Thank you very much.

@quisido
Copy link
Collaborator

quisido commented Jul 8, 2019 via email

@quisido quisido self-assigned this Jul 8, 2019
@quisido quisido added the feature A new feature is requested. label Jul 8, 2019
@quisido
Copy link
Collaborator

quisido commented Jul 20, 2019

Sorry for the delay. This fix will be out today in 2.1.5.

I have tested it in the docs directory of this repository, wherein it seems to be working correctly:
image

It's an odd fix because the reducers are self-referential (the dispatch parameter references all other reducers, including itself), so if you run into any issues or bugs, just let me know, and I'll dig into it further.

As an addendum to your personal use case, you may want type to be keyof State or an enum of properties that are arrays (and can be filtered).

Thanks again for bringing this to my attention!

@quisido quisido added this to the 2.1.5 milestone Jul 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature A new feature is requested.
Projects
None yet
Development

No branches or pull requests

2 participants