-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Actions aren't resolved with generic slice return types #689
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
Comments
Out of curiosity, why are you trying to specify a return type there in the first place? |
@markerikson we have @typescript-eslint/explicit-module-boundary-types turned on in our project. So when I add |
Well, that's why. Turn off that lint rule :) If it compiles and runs fine without explicitly declaring a return type, then you don't need it here. Lint rules are supposed to help you. If a lint rule doesn't "spark joy", turn it off :) |
@markerikson hah, fair point. I might just do that :). |
Yeah, have to agree very strongly with Mark there. RTK enables you to write a lot less TS code, but when you start specifying it's types manually, you're in for a very bad time. I'd also suggest turning that rule off. |
Thanks a lot @phryneas and @markerikson, I'll do without the rule. |
When adding a return type to a generic createSlice function the action types are no longer resolved.
Here is the example from the docs with the return type added:
The start and success actions are not resolved:
Property 'success' does not exist on type 'CaseReducerActions<{ magic(state: { data?: string; status: "loading" | "finished" | "error"; }): void; }>'.
.Removing the return type allows the actions to resolve.
Am I providing the wrong return type or do I have to resolve the actions in another way?
Here is a playground with this code and errors.
I noticed createSlice is being updated, so maybe this issue will be resolved in the PR: #637.
The text was updated successfully, but these errors were encountered: