I've encountered a situation where I'm using a package that includes a function with this specific declaration:
const getList: (params?: ListRequestParams | undefined) => Promise<void | {
items: any[];
pageInfo: PageInfo;
}>
My attempt to destructure the returned value from calling this function looks like this:
const {items, pageInfo} = await getList(some_param);
However, this approach doesn't seem to work properly, possibly due to the inclusion of 'void' in the return type. Resorting to using a temporary variable does the job but feels inelegant.
const temp = await getList(some_params);
if(temp !== undefined)
{
const { items, pageInfo } = temp;
}
I'm curious if there are better ways to handle destructuring in this scenario. Appreciate any insights or suggestions. Thank you.