Skip to content

Super constructor return ignored #7710

Closed
@whitneyit

Description

@whitneyit

TypeScript Version:

nightly (1.9.0-dev.20160313)

Code

class Collection extends Array {

    constructor(...args) {
        const first = arguments[0];
        if (args.length === 1 && typeof first === 'number') {
            super(first, null);
            this.pop();
        } else {
            super(...args);
        }
    }

}

const a = new Collection(3, 2, 1);
const b = new Collection(3);
console.log(a, b);

Expected behavior:
The Array is correctly subclassed and the instances are created correctly.

Actual behavior:
The instances are not created correctly.

Notes:

Questions:

  • Should this be part of core?
interface ArrayConstructor {
    new (...items: any[]): any[];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions