I want to handle the cases when a promise is fulfilled and when it is rejected separately. I saw that with my code the first function passed to then is always called, even when the promise is rejected.
I have code like this with the issue explained in a comment:
dispatch(reduxActionCreatorHere(/* ...)*/).then((d) => {
if (d.error) { // TS error: `error` missing from `d`, although the promise is rejected and the `error` field is accessible in pure JS (tested in Chromium DevTools)
// ...
}
// ...
}
And like this:
export const resetPassword = createAsyncThunk(
"auth/resetPassword",
async (options: { email: string }, thunkAPI) => {
debugger;
return await new Promise<void>((resolve, reject) => {
setTimeout(() => {
requestPasswordCrud(options.email).then(
() => {
console.log("password reset");
resolve();
},
() => {
reject();
}
);
}, 1000);
});
}
);
Update 1
The actual error message is:
Property 'error' does not exist on type 'PayloadAction<void, string, { arg: { email: string; }; requestId: string; }, never> | PayloadAction<unknown, string, { arg: { email: string; }; requestId: string; aborted: boolean; condition: boolean; }, SerializedError>'.
Property 'error' does not exist on type 'PayloadAction<void, string, { arg: { email: string; }; requestId: string; }, never>'. TS2339