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