Within this class object, I have an instance of a class that I am unable to call its functions within. Despite the IDE allowing me to call the getPoistionDiagram function:
export class NodeW {
childrenIds: string[];
diagram?: {
coordinates: {
x: number;
y: number;
};
} | null;
nodeId: string;
parameters: {
childrens?: string[];
name?: string;
nodeNumber?: string;
original?: string;
cases?: any;
parent?: any;
extra?: any;
copyIds?: any;
copyNames?: any;
};
type: NodeType;
constructor(
childrenIds: string[],
nodeId: string,
parameters: {},
type: NodeType,
diagram?: { coordinates: { x: number; y: number } },
) {
this.childrenIds = childrenIds;
this.diagram = diagram;
this.nodeId = nodeId;
this.parameters = parameters;
this.type = type;
}
getPositionDiagram(i: number): { x: number; y: number } {
return {
x: !this.diagram ? 20 * 10 : this.diagram.coordinates.x,
y: !this.diagram ? i * 120 : this.diagram.coordinates.y,
};
}
}
export class NodesArray {
private nodes: NodeW[];
private createNewNodesService?: CreateNewNodesService;
constructor(nodes?: NodeW[]) {
if (nodes && nodes.length > 0) {
this.nodes = nodes;
} else {
this.nodes = DEFAULT_NODE_ARRAY();
}
}
getNodes(): NodeW[] {
return this.nodes;
}
setNodes(nodes: any) {
this.nodes = nodes;
}
getParentNode(nodeId: string) {
for (let i = 0; i < this.nodes.length; i++) {
if (this.nodes[i].childrenIds.includes(nodeId)) {
return this.nodes[i].nodeId;
}
}
return null;
}
}
When I try to access the method inside the attribute, it does not allow me to access the methods of NodeW and also indicates that it is not of type NodeW when checked.
Could this issue be related to the forEach() method used?