具有以下代码:
const handleNodes = (node: Node | Node[]) => {
if (Array.isArray(node)) {
return [{}];
}
return {};
};
我想要这样的结果:
handleNodes([{}]) // infer that this returns an array
handleNodes({}) // infer that this returns an object
我怎么能做到这一点?我试着用conditional types,但没有成功.