I am working on creating a custom Array2D class by extending the Array class in JavaScript. My goal is for the constructor to accept any number of arguments, each representing an array of type T. Here is the current implementation:
class Array2D<T> extends Array<T[]> {
constructor(...args: T[][]) {
super(...args)
}
static of(...args: T[][]) {
return new Array2D(...args)
}
}
However, I am encountering an error in TypeScript:
Types of property 'of' are incompatible.
Type '<T>(...args: T[][]) => Array2D<T>' is not assignable to type '<T>(...items: T[]) => T[]'.
Types of parameters 'args' and 'items' are incompatible.
Type 'T' is not assignable to type 'T[]'.
Could someone please help me understand what this TypeScript error means and suggest a solution?