-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static class properties are set after class creation, even for inherited read-only properties #46912
Comments
Uncaught TypeError: Cannot set property Symbol(Symbol.species) of function Promise() { [native code] } which has only a getter
If you want to do this you'll need to turn on the spec compliance setting |
I tried this {
"compilerOptions": {
"target": "es5",
"useDefineForClassFields": true
},
"include": [
"**/*.ts"
],
"exclude": [
"node_modules"
]
} |
@IllusionMH I think you misunderstand. One of the important features of TypeScript is being able to use future syntax transpiled to older versions in a way that works identically (or as close as possible) to future specifications. Being able to transpile ESNext classes into an equivalent ES5 implementation is one of the things TypeScript is intended to be able to do. It's just that this edge case doesn't seem to be covered by it due to a bug of some sort. |
Sorry, I've missed "run exactly same" and was confused by expected example.
What version are you using and are you sure that this config used? You should get |
Huh, it was definitely using my |
@GrantGryczan Directly passing filenames to |
Ah, okay, good to know. |
Bug Report
π Search Terms
class extends promise symbol species getter inherit read-only static
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
Here is an example TypeScript file:
index.ts
π Actual behavior
If I run
tsc index.ts
with notsconfig.json
, it emits this file:index.js
Running this throws an error on line 24:
Uncaught TypeError: Cannot set property Symbol(Symbol.species) of function Promise() { [native code] } which has only a getter
This is due to the fact that line 24 attempts to set the
Symbol.species
property of the class after the class is already created, which JavaScript (in strict mode) does not allow. Note that this only applies in strict mode.Or alternatively, if I run
tsc index.ts --target es2015
, it emits this file:index.js
This has the same issue on line 6, and for the same reason.
π Expected behavior
I expect the JS compiled from
index.ts
to run exactly the same, without errors, as the following plain JavaScript code:The text was updated successfully, but these errors were encountered: