TypeScript error with Symbol.species example from MDN

Viewed 187

With this code (which is equivalent to a sample at MDN):

class MyArray<T> extends Array<T> {
    static get [Symbol.species]() { return MyArray }
}

I get this error (with TypeScript 3.8.3):

Class static side 'typeof MyArray' incorrectly extends base class static side '{ isArray(arg: any): arg is any[]; readonly prototype: any[]; from<T>(arrayLike: ArrayLike<T>): T[]; from<T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; from<T>(iterable: Iterable<...> | ArrayLike<...>): T[]; from<T, U>(iterable: Iterable<...> | ArrayLike<...>, mapfn: (v: T, k: nu...'.
  Types of property '[Symbol.species]' are incompatible.
    Type 'typeof MyArray' is not assignable to type 'ArrayConstructor'.
      Type 'typeof MyArray' provides no match for the signature '(arrayLength?: number | undefined): any[]'.

What could be wrong?

0 Answers
Related