Support downleveling classes that extend frozen bases#62397
Support downleveling classes that extend frozen bases#62397gibson042 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the TypeScript compiler's __extends helper function to support downleveling classes that extend frozen base classes. The change replaces direct property assignment to this.constructor with Object.defineProperty when available, which avoids the "override mistake" that occurs when the base class has a non-configurable, non-writable constructor property.
- Updated the
__extendshelper to useObject.definePropertyfor setting the constructor property when available - Added fallback to direct assignment for older environments that don't support
Object.defineProperty - Ensures compliance with the ECMAScript specification by creating a non-enumerable constructor property
|
I am not sure we need this at all; ES5 is being deprecated in 6.0 and will not be implemented in 7.0. |
In the meantime, this can fix some very real problems for the remainder of 5.x and the entirety of 6.x. Is there any reason to stick with the incorrect implementation? |
|
It's very common that people have dependencies on incorrect behavior and we're trying to minimize friction for people moving to 6.0. The user-side workarounds here are fairly straightforward (inject your own Closing as the linked issue is not approved for PRs. |
Are you suggesting that people are depending upon an error being thrown when evaluating the definition of a class that uses
I don't consider those workarounds to be practical for something as common as |
|
TypeScript users publishing to npm registry are publishing the resulting code, so a user replacing the downleveler is not a workaround. |
Fixes #43450
Assignment to
this.constructorfails whenthisinherits from an object with a non-configurable non-writableconstructorproperty (the so-called "override mistake"): TypeScript Playground.This PR updates
extendsHelperto useObject.definePropertywhen available, which is immune to the override mistake (and incidentally also creates a non-enumerableconstructorproperty as required by the specification).