-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Hello,
I've been using typescript-fsa-redux-thunk combined with typescript-fsa-reducers for quite some time now very happily - thankyou!
Today, I upgraded several of my projects to Typescript 3.4, at which point many of my thunk-based actions suddenly were not working properly in my reducers. Specifically, I have simple async actions defined somewhat like:
const doThing = createAsyncAction<void, number>("DO_THING",
async () => {
return 1;
},
);with reducers structured like:
...
.case(doThing.async.done, (state, {result}) => ({
...state,
newValue: result,
}))
...This worked fine in the past, I was able to use them simply in calls like dispatch(doThing.action()), reducers worked as expected.
Today, I can define the actions fine, but in the reducers, I receive this typescript compilation error:
Type '(action: AnyAction) => action is Action<Failure<void, Error>>' is not assignable to type '(action: AnyAction) => action is Action<{ params: void; } & { error: Error; }>'.
Type predicate 'action is Action<Failure<void, Error>>' is not assignable to 'action is Action<{ params: void; } & { error: Error; }>'.
Type 'Action<Failure<void, Error>>' is not assignable to type 'Action<{ params: void; } & { error: Error; }>'.
Type 'Failure<void, Error>' is not assignable to type '{ params: void; } & { error: Error; }'.
Type '{ params?: void | undefined; } & { error: Error; }' is not assignable to type '{ params: void; } & { error: Error; }'.
Type '{ params?: void | undefined; } & { error: Error; }' is not assignable to type '{ params: void; }'.
Property 'params' is optional in type '{ params?: void | undefined; } & { error: Error; }' but required in type '{ params: void; }'.
It looks like it is due to this rule in typescript-fsa:
export type Success<Params, Result> =
({params: Params} | (Params extends void ? {params?: Params} : never)) &
({result: Result} | (Result extends void ? {result?: Result} : never));Basically, Params extends void fires here, meaning params should be defined as params?, but I think they're being passed in as params: void.
I hope I interpreted that issue correctly. If I have a type other than void for the thunk param, then everything compiles fine. This code worked prior to Typescript 3.4, so I'm presuming a more thorough type checking has occurred here to catch this particular one.
Relevant packages:
"typescript": "^3.4.5",
"typescript-fsa": "^3.0.0-beta-2",
"typescript-fsa-reducers": "^1.2.1",
"typescript-fsa-redux-thunk": "^2.0.0-beta.11",
Let me know if I can provide any other details!