My code is as follows:
export function testGraph({ id = 0, name = "test", nodes = [] }): Graph {
if (nodes.length === 0) {
const dummyNode = testNode({});
return new Graph(id, name, [dummyNode]);
}
return new Graph(id, name, nodes);
}
export function testDatabase({ id = 0, name = "test", graphs = [] }): Database {
if (graphs.length === 0) {
const dummyGraph = testGraph({ nodes: new Array(new Node(0)) });
return new Database(id, name, [dummyGraph]);
}
return new Database(id, name, graphs);
}
But this gives me the following error:
Type 'Node[]' is not assignable to type 'never[]'.
Type 'Node' is not assignable to type 'never'.
40 const dummyGraph = testGraph({ nodes: new Array(new Node(0)) });
~~~~~
I can't seem to understand why this is automatically inferring 'never' type. I tried explicitly declaring the type but to no luck.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…