Here is the code snippet:
const handleNodes = (node: Node | Node[]) => {
if (Array.isArray(node)) {
return [{}];
}
return {};
};
The desired result is:
handleNodes([{}]) // infer that this returns an array
handleNodes({}) // infer that this returns an object
Is there a way to achieve this? I attempted to utilize conditional types, but faced some challenges.