I have a resolver function which might have an optional second parameter called otherParams. I would like that Typescript checks if the function returned from createResourceThunk is also called with the parameter otherParams if it is defined in the resolver function. How can I do that? Minimal reproducable example here
export function createResourceThunk<T, Params, A, OtherParams extends A | never>(
actions: ResourceActions<T>,
resolver: (params: Params, otherParams: OtherParams) => Promise<T>
) {
return function(params: Params, callbacks: Callbacks<T>, otherParams: OtherParams) {
return async (dispatch: Dispatch) => {
dispatch(actions.startAction());
try {
const data = await (otherParams ? resolver(params, otherParams) : resolver(params));
...
} catch (error) {
...
}
};
};
}
Currently it is expecting always a third Parameter in the call of the returned function
A | never
? That is immediately reduced toA
no matter what. Also, in your minimal reproducible example I'd suggest showing a few use cases of callingcreateResourceThunk()
and calling what it returns, withresolver
parameters that do / do not take a second parameter, so that folks can demonstrate what's supposed to be happening. Otherwise you will get the answer "just makeotherParams
optional everywhere with a?
".