Closed
Description
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:
- This code works in the babel repl.
- Not only does the above code not work in the playground, it needs to following addition to
IArrayConstructor
to get it to not squark. - This seems related to Return value of super() calls not used for
this
#7574.
Questions:
- Should this be part of core?
interface ArrayConstructor {
new (...items: any[]): any[];
}