I have function:
export const paramsFactory = (params: paramsType) => {
return ...
}
In another component I have the same function but after return … it also contains await getPageInfo({ page: 1 }).
So I need pass callback as a second param to this function. And how to use it correctly?
I have something like that:
export const paramsFactory = (params: paramsType, callback?: () => Promise<void>) => {
return async (...) => {
...
if (callback) {
await callback()
}
}
}
await callback() as a part of return statement.
When I use it paramsFactory(params, getPageInfo({ page: 1 })) I get
TS2345: Argument of type ‘Promise’ is not assignable to
parameter of type ‘() => Promise’. Type ‘Promise’
provides no match for the signature ‘(): Promise’.
>Solution :
use
paramsFactory(params, () => getPageInfo({ page: 1 }))