Typescript: ES5 run-time for "extends" keyword incompatible with ES6

Created on 27 Oct 2017  路  3Comments  路  Source: microsoft/TypeScript

The ES5 transpiled output from the Typescript compiler for the extends keyword isn't consistent with the current standard behavior of ES6 Javascript, and also isn't consistent with the way Typescript checks the types at compile-time.

Code

class List extends Array { }

alert(new List instanceof List);

Try it on the playground where the code is transpiled to ES5 by default.

Expected behavior:

An alert showing true.

Actual behavior:

An alert showing false.

Question

Most helpful comment

https://github.com/Microsoft/TypeScript/wiki/FAQ#why-doesnt-extending-built-ins-like-error-array-and-map-work

Also on https://babeljs.io/docs/plugins/transform-es2015-classes/

Built-in classes such as Date, Array, DOM etc cannot be properly subclassed due to limitations in ES5

All 3 comments

It is not currently viable to extend built-ins.

A potential solution is proposed in #15397

https://github.com/Microsoft/TypeScript/wiki/FAQ#why-doesnt-extending-built-ins-like-error-array-and-map-work

Also on https://babeljs.io/docs/plugins/transform-es2015-classes/

Built-in classes such as Date, Array, DOM etc cannot be properly subclassed due to limitations in ES5

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Was this page helpful?
0 / 5 - 0 ratings