-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
State argument on createSlice is no longer inferred with typescript beta 4.8 and they do not plan to fix it #2543
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
Hmm. @phryneas , you know way more about the |
In trying to fix this, I've discovered that even in strict mode, nothing enforces that the payload argument of a slice is typed - and it defaults to any. And in trying to fix that, even on 4.7, it ends up requiring the user to type not just the action parameter but the state one too. |
Essentially, it breaks |
For historical context why that type is there: #149 (comment) |
btw I worked out how to enforce a payload type is always provided:
For ts 4.7, I think it does the same enforcement that prepare actions match, it does not require a typed state argument and it enforces that the payload can never be any, unknown or a empty object (but the argument can be missing). Since it forces typing actions on everyone using typescript, I don't know if you want to include it. Unfortunately though, it does not help with the infer of the state argument in 4.8. |
Either we fixed this or it isn't enough of an issue that people are complaining :) |
See the bug on the typescript repo: microsoft/TypeScript#49307 (comment)
It seems the typescript team will not fix this. Maybe the redux-toolkit types can be fixed to be compatible and still infer? else the examples and documentation need changing to say that the state argument will not be inferred and need to be explicitly provided.
cc/ @markerikson
The text was updated successfully, but these errors were encountered: