We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
decorator, target:ES2022, experimentalDecorators, emitDecoratorMetadata, TC39
This changed between target:ES2021 and target:ES2022
https://github.com/paulsmithkc/typescript-decorators
tsconfig.json
{ "compilerOptions": { "target": "ES2022", "module": "commonjs", "outDir": "dist", "declaration": true, "experimentalDecorators": true, "emitDecoratorMetadata": true }, "include": ["src"], "exclude": ["node_modules", "dist"] }
src/index.ts
function setting(defaultValue: string): any { function settingExperimental(target: unknown, property: string | symbol): void { console.log('settingExperimental', { defaultValue, target, property }); target[property] = process.env[String(property)] || defaultValue; return; } function settingTC39(_target: unknown, context: ClassFieldDecoratorContext): () => string { return function (): string { console.log('settingTC39', { defaultValue, target: this, context, type }); return process.env[String(context.name)] || defaultValue; }; } return function (target: unknown, context: string | symbol | ClassFieldDecoratorContext) { if (typeof context !== 'object') { return settingExperimental(target, context); } else { return settingTC39(target, context); } }; } console.log('CLASS DECLARATION.'); class Config1 { @setting('default_1') SETTING_ONE: string; } class Config2 extends Config1 { @setting('default_2') SETTING_TWO: string; } console.log('OBJECT INSTANTIATION.'); const configInstance = new Config2(); console.log({ prototype1: Config1.prototype, prototype2: Config2.prototype, SETTING_ONE: configInstance.SETTING_ONE, SETTING_TWO: configInstance.SETTING_TWO, }); if (!configInstance.SETTING_ONE) { throw new Error('SETTING_ONE NOT INITIALIZED'); } if (!configInstance.SETTING_TWO) { throw new Error('SETTING_TWO NOT INITIALIZED'); } console.log('DONE.');
run with:
tsc --project tsconfig.json && node dist/index.js
When targeting ES2022:
When targeting ES2021:
When targeting an version of ECMA script:
The generate code differs from ES2021 to ES2022, which is what is causing this issue.
ES2021
class Config1 { } class Config2 { }
ES2022
class Config1 { SETTING_ONE; } class Config2 extends Config1 { SETTING_TWO; }
The text was updated successfully, but these errors were encountered:
This is working as intended. See: https://www.typescriptlang.org/tsconfig/useDefineForClassFields.html
And also: #48814
Sorry, something went wrong.
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
π Search Terms
decorator, target:ES2022, experimentalDecorators, emitDecoratorMetadata, TC39
π Version & Regression Information
This changed between target:ES2021 and target:ES2022
β― Playground Link
https://github.com/paulsmithkc/typescript-decorators
π» Code
tsconfig.json
src/index.ts
run with:
π Actual behavior
When targeting ES2022:
When targeting ES2021:
π Expected behavior
When targeting an version of ECMA script:
Additional information about the issue
The generate code differs from ES2021 to ES2022, which is what is causing this issue.
ES2021
ES2022
The text was updated successfully, but these errors were encountered: