TypeScript: Fail to import `classPrivateFieldGet` from tslib when `"importHelpers": true`
I am testing out the lastest ECMA private fields. I get an error when importHelpers enabled:
This syntax requires an imported helper named '__classPrivateFieldGet' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.ts(2343)
I’m not sure if there’s pending work on the tslib, so I’m repoting this anyway.
TypeScript Version: 3.8.1-rc TS Lib Version: 1.1.0
Search Terms: tslib classPrivateFieldGet
Code
class A {
#a: number
constructor() {
this.#a = 1
}
}
Expected behavior:
This should compile
Actual behavior:
Shows an error on tslib
Playground Link:
Related Issues:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 22 (6 by maintainers)
Same issue with TS 3.9.3 and tslib 2.0.0
With Typescript 3.8.2 (also applies with TS 3.9.3) and tslib 2.0.0, I have got a runtime Error
ReferenceError: __classPrivateFieldGet is not definedI’m experiencing this on
4.8.4but slightly different error, not sure if also caused byimportHelpersSame issue here with
typescript3.8.3 andtslib1.11.1.I have a few additional observations:
importHelpers: trueoption and emit all required helpers (including__classPrivateFieldGetand__classPrivateFieldSet) into the js file. When the compiled file references other files via imports the behaviour @pirix-gh described occurres.module: "CommonJS"is set, it imports all helpers just as you would expect. However, whenmodule: "ESNext"or"module: "ES2015"it does not import__classPrivateFieldGetand__classPrivateFieldSet(other helpers like__awaiterare imported though)Just add
tslib^2.4.1to resolutions, And runnpm install, the lock file will update, removetslib^2.4.1on resolutions just added, runnpm install, again, the lock file will be updated again, and this problem will be fixedThis is again a bug in
4.8.4. Easy to reproduce:tsconfig.json
index.ts