-
-
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
takeLatest and similar should typecheck pattern parameter. #1543
Comments
This is something I'd be willing to open a PR for if wanted. |
PRs are welcome. I would like to see how you implement the typecheck for takeEvery. It is complex since |
@BenLorantfy will you be able to prepare a PR for this? if not we might close this issue because we are not actively working on typings, this is a community effort, not ours. @aikoven is it possible to type check this? |
I took a quick look but it looks pretty complicated and I’m not sure where to start. In theory it’s possible (using generics) but I’m not sure how to fit it into the existing typings. I think this would be a useful type check though, so I don’t think this should be closed. |
This indeed looks pretty complicated, since you can use many different things as This is how export type ActionType = string | number | symbol;
export type StringableActionCreator<A extends Action = Action> = {
(...args: any[]): A;
toString(): string;
};
export type ActionSubPattern<Guard extends Action = Action> =
| GuardPredicate<Guard, Action>
| StringableActionCreator<Guard>
| Predicate<Action>
| ActionType
export type ActionPattern<Guard extends Action = Action> =
| ActionSubPattern<Guard>
| ActionSubPattern<Guard>[]; The path we're interested in is We could parametrize it like this: type ActionType<A extends Action = Action> = A['type']; But unfortunately in Redux typings the type of |
if So if change
The result will be as expected. Below code will produce type error
The only this which confuse me is form of |
Closing due to inactivity. If this is still something worth discussing please reply and I will reopen to help. Thanks! |
This isn't a bug report per se, but more of a suggestion on how to improve the typings.
As a user, I'd expect the above code to throw an error, because 'blablabla' is not equal to 'LOAD_DATA'. This code should be fine:
This should work similarly for takeEvery, take, etc.
The text was updated successfully, but these errors were encountered: