So im trying to make a typescript file for a network and there are three files involved.
a _Node.ts, Edge.ts, and a Graph.ts
These three files look like so:
_Node.ts
interface _Node {
  data: any;
  neighbours: number[];
}

class _Node {
  constructor(data) {
    // this data is an arbitrary thing with which I can create any object
    this.data = { ...data };
    // the neighbours bit is explicity set from the code outside
    this.neighbours = [];
  }
}

export { _Node };

Edge.ts
interface Edge {
  start: number;
  end: number;
  data: any;
}

class Edge {
  constructor(start, end, data) {
    this.start = start;
    this.end = end;
    this.data = { ...data };
  }
}

export { Edge };

Graph.ts
import { _Node } from "./_Node";
import { Edge } from "./Edge";

interface Graph {
  nodes: _Node[];
  edges: Edge[];
}

class Graph {
  constructor(nodes, edges) {
    this.nodes = nodes;
    this.edges = edges;
    // execute Internal methods
    // this.printData();
  }

  // test function
  printData() {
    const message =
      "This is a graph with " +
      this.nodes.size + // this gives an error "Property size doesn't exist on nodes"
      " nodes and " +
      this.edges.size +
      " edges";
    console.log(message);
  }
}


The last line of node.size and edges .size give a VS code error of something like the property size doesn't exist on them despite me declaring them as arrays of the nodes and things - is there a way to fix it?

Typescript class made up of an array of other classes gives an error
You're looking for
this.edges.length
as specified by
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length
size is not a valid property or function
