Hello everyone,
I have this trivial code inspired by a case in a production codebase ()
type GNode = {
id: number;
// foo: number; // uncomment for problems
}
type GGNode = GNode & {
tag: string;
}
type Graph = {
nodes: GNode[];
}
type GGraph = Graph & {
nodes: GGNode[];
}
//
type AGNode = {
id: number;
}
type AGGNode = AGNode & {
tag: string;
}
type AGraph = {
nodes: AGNode[];
}
type AGGraph = AGraph & {
nodes: AGGNode[];
}
const x = {} as GGraph | AGGraph
x.nodes.map(({ id }) => id)
If I uncomment the line with foo, I get this error:
This expression is not callable.
Each member of the union type '((<U>(callbackfn: (value: GNode, index: number, array: GNode[]) => U, thisArg?: any) => U[]) & (<U>(callbackfn: (value: GGNode, index: number, array: GGNode[]) => U, thisArg?: any) => U[])) | ((<U>(callbackfn: (value: AGNode, index: number, array: AGNode[]) => U, thisArg?: any) => U[]) & (<U>(callbackfn: (value: AGG...' has signatures, but none of those signatures are compatible with each other.
I understand what the error is saying, but I don't understand the reason why an extra field in the underlying type causes this to fail. If someone has any pointers - a link where I can read more is totally enough - I'd be grateful. I tried googling and found a lot of pre-4.2 posts, but these, as far as I understand, do not apply anymore.
Thank you in advance!