You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actually, it doesn't - it's impossible to subclass builtin classes like Array in ES5, because there's no way to tell the Array constructor to use your subclass's prototype.
If you transpile this with Babel, new Collection creates a plain array which does not inherit from Collection.prototype, defeating the whole purpose of subclassing.
(Since it wasn't explicitly answered) The reason the compiler complains about the two super() calls is that Collection extends Array and not Array<T>. The construct signature that takes in array elements only exists in the generic formnew<T>(...items: T[]): T[] .
So Collection should either be class Collection<T> extends Array<T> or class Collection extends Array<any> depending on what the intended use is.
TypeScript Version:
nightly (1.9.0-dev.20160313)
Code
Expected behavior:
The
Array
is correctly subclassed and the instances are created correctly.Actual behavior:
The instances are not created correctly.
Notes:
IArrayConstructor
to get it to not squark.this
#7574.Questions:
The text was updated successfully, but these errors were encountered: