Skip to content

Conversation

@rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Mar 5, 2025

The experimentalDecorators flag is legacy from TypeScript 3.9.

Since then, decorators have gone through a large change and their new syntax, which is enabled by default in TypeScript 5+, looks very different.

Keeping this old flag enabled locks users into old decorator typings which are deprecated, plus because of the way our defaults are applied these flags are not overridable.

Instead, don't set experimentalDecorators at all, and have users opt in to legacy syntax if they must.

This is technically breaking, but I'm pretty sure this will affect such a negligible fraction of users that I think it's worth it.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The `experimentalDecorators` flag is legacy from TypeScript 3.9.

Since then, decorators have gone through a large change and their new
syntax, which is enabled by default in TypeScript 5+, looks very
different.

Keeping this old flag enabled locks users into old decorator typings
which are deprecated, plus because of the way our defaults are applied
these flags are not overridable.

Instead, don't set `experimentalDecorators` at all, and have users opt
in to legacy syntax if they must.

This is technically breaking, but I'm pretty sure this will affect such
a negligible fraction of users that I think it's worth it.
@rix0rrr rix0rrr requested a review from a team March 5, 2025 18:36
@mrgrain mrgrain disabled auto-merge March 5, 2025 19:35
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Mar 5, 2025

Let's be sure to merge this when we do TypeScript 5.8

@kaizencc kaizencc added this pull request to the merge queue Mar 13, 2025
Merged via the queue into main with commit 6427921 Mar 13, 2025
73 checks passed
@kaizencc kaizencc deleted the huijbers/no-experimental-decorators branch March 13, 2025 18:31
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Oct 6, 2025
This upgrades jsii to a version with support for type intersections.

Changes around decorators:

* Because this is switching to a newer version of jsii [that doesn't set `experimentalDecorators: true` anymore by default](aws/jsii-compiler#1828), we need to update the typing for the `@MethodMetadata` decorator ([ref](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#decorators)).
* Because the `framework-integ` package can see the source `.ts` files from `aws-cdk-lib`, it can see the presence of the decorators. The code must type check, so we must switch `experimentalDecorators` to the same value in that package (`false`). Some example code used a legacy decorator which had to be rewritten to be somewhat equivalent: the exact  example cannot be recreated with modern decorators.
* The emulation of modern decorators behaves slightly differently depending on the target (it either uses the `static { }` JS syntax if available in ES2022+, or tries to emulate that syntax). If the behavior is emulated, the `CONSTRUCT_INJECTION_ID` property can never be read from the class -- it always shows up as `undefined`. Upgrade to ES2022 across the board to generate the right polyfill code. This is supported by Node 16+.
  * Jsii forces ES2020 by default. To switch everything to ES2022, we need to eject from the jsii autogenerated config everywhere.

I also bumped the Node type definitions, which led to a couple more eslint violations that needed to be fixed.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants