In my code, I have a customizedHook that returns a value of type typeXYZ || unknown
. However, when I try to destructure the returned value, I encounter an error
TS2339: Property 'xyz' does not exist on type 'unknown'
, even though the data actually returns as xyz: {} and abc: ['string1', 'string2']. How can I resolve this issue?
export function useAPICall(): typeXYZ || unknown {
const {data} = useQuery(['apiCallData'], async () => {
const value: typeABC = (await cbFunction()) as typeABC;
return value?.defaultValue;
});
return {data};
//console.log(data)
//{xyz: {abc: 'asdasda', cde: 'xzczxc'}, abc: ['aaaa','bbbb','cccc']}
}
const {xyz: {}, abc: string[]} = useAPICall()