-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Bug (?) with "action.payload" type inference in AsyncThunkFulfilledActionCreator #1605
Comments
This is actually interesting. |
Yes, per the commit message, the change there was supposed to fix another type inference bug that happened in 1.6.0: |
The problem is that with the addition of rejecting and fulfilling with additional Since you should be using the generic arguments as soon as you are using But if you have the time and resources to experiment around and find a type hack that works in every situation, a PR would be very welcome :) |
@markerikson The way to handle errors with I suggest to roll back this change for now, because it breaking (in fact), and leave it until the next minor version. Patches should not contain breaking changes. |
The documentation example you linked to is a JavaScript example, not a TypeScript example. Also, this cannot simply be rolled back as it is a fix for a much more serious type bug. Your use case was frankly just working for you purely accidentally and never an intended use case - we would never have assumed that someone would want to use As I said, PRs to make this work (without breaking the serious #1156) are welcome. |
@phryneas ok, got it. Indeed, it is my mistake that I did not read everything carefully :) Since this is probably not a bug, I close the issue. Thanks for the clarification! |
@e965 yeah, the other factors here are that:
If we did something like intentionally rewriting our types to remove public symbols or completely change generic arguments, then yeah, I'd classify that as a true "breaking change" worthy of a major version. But in most cases, what we're doing is trying to improve behavior with small tweaks, and in some cases that may unfortunately end up causing compile issues. Frankly, this is a tradeoff that we all have to deal with as TS users - you accept the risk of additional complexity up front, in order to get better safety for the codebase as a whole. |
Situation - I have a promise that returns some data. This promise may return with an error, so it is wrapped in a
try/catch
(where the error is handled and I get the payload using thethunkAPI.rejectWithValue
function).The problem - on version
1.6.1
, the value of the payload returned in thethunk.fulfilled
case was the same as the value in the promise. As of version1.6.2
, an unknown type is returned. Without atry/catch
wrapper, thunk works as expected and returns the correct type.Demos:
The text was updated successfully, but these errors were encountered: