Skip to content

Custom array class methods disappear #17603

@nicholaschiang

Description

@nicholaschiang

Current behavior

Custom array class methods disappear:

class MyArray extends Array<number> {
  public toString(): string {
    return 'Custom toString method called!';
  }

  public toDB(): string[] {
    return Array.from(this.map((t) => t.toString()));
  }
  
  public static fromDB(record: string[]): MyArray {
    return new MyArray(...record.map((t) => Number(t)));
  }
}

 // Logs an empty array `[]`
console.log('MyArray:', new MyArray());
// Logs an empty string (calls Array#toString instead of MyArray#toString)
console.log(`MyArray: ${new MyArray().toString()}`); 
// Logs `undefined` (even though I defined a MyArray#toDB method)
console.log('MyArray toDB:', new MyArray().toDB);
// Logs `[Function (anonymous)]` (so static methods are preserved)
console.log('MyArray fromDB:', MyArray.fromDB);

Desired behavior

Cypress should compile that custom MyArray class and it's methods properly.

// Should log `Custom toString method called!` instead of an empty string
console.log(`MyArray: ${new MyArray().toString()}`); 
// Should log `[Function (anonymous)]` instead of `undefined`
console.log('MyArray toDB:', new MyArray().toDB);

Test code to reproduce

See description above.

Cypress Version

Cypress package version: 8.1.0
Cypress binary version: 8.1.0
Electron version: 12.0.0-beta.14
Bundled Node version: 14.15.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions