Here is a function that I have:
export const paramsFactory = (params: paramsType) => {
return ...
}
In a different component, the same function also contains await getPageInfo({ page: 1 })
after the return .... To make this work, I need to pass a callback as a second parameter to the function and then use it correctly. Here is what I have tried:
export const paramsFactory = (params: paramsType, callback?: () => Promise<void>) => {
return async (...) => {
...
if (callback) {
await callback()
}
}
}
The issue arises when trying to use await callback()
as part of the return statement like
paramsFactory(params, getPageInfo({ page: 1 }))
. This results in an error message:
TS2345: Argument of type 'Promise' is not assignable to parameter of type '() => Promise'. Type 'Promise' provides no match for the signature '(): Promise'.