-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
feat(core): support usage of non-experimental decorators with TypeScript 5.0 #49492
Conversation
e3a18bf
to
4191dff
Compare
13cdd66
to
e222e90
Compare
e222e90
to
f0a5fca
Compare
f0a5fca
to
2ce2e24
Compare
07a6bfc
to
c5e09b1
Compare
597c8ef
to
cb3844c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: fw-core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should discuss the level of support commitment we're making in this PR for standard decorators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have some sort of test for this?
There is a linked CLI E2E test that demonstrates the functionality. If there is a more appropriate place for some tests, i can add them as well. |
cb3844c
to
6bbb68a
Compare
@clydin it looks like we the commit message might need an update as well, since the implementation has changed. |
6d5d780
to
4069209
Compare
…ipt 5.0 Previously, attempting to turn off the `experimentalDecorators` TypeScript configuration option within an Angular project would result in build time errors. These errors were due to an exposed Decorator signature from `@angular/core` that TypeScript thought was incompatible with standard decorators. However, Angular's class decorators (`Component`, `Directive`, `Pipe`, `Injectable`, `NgModule`) are actually already compatible with standard decorators. The export types for the decorators only needed to be updated to reflect that compatibility. With the updated exported types, applications will now successfully compile and execute in AOT mode with one important dependency injection caveat explained in the note below. For JIT mode applications that are built with the Angular CLI, `@ngtools/webpack`, or use `tsickle`, there were also no additional changes required. These tools automatically convert property decorators (now called field decorators) at build time to store Angular property metadata directly on the relevant class. Building with these tools is the overwhelmingly common method of building an application. Any applications that do not use one of these tools will not function at runtime in JIT mode if using standard decorators. The behavior and code for when experimental decorators is enabled has been left intact. NOTE: Angular constructor dependency injection that requires parameter decorators is not supported. The standard decorator specification does not support parameter decorators. The `inject` function must be used for all cases that previously required a parameter decorator. This includes such decorators as `Inject`, `Optional`, `Self`, `SkipSelf`, `Host`, and `Attribute`. Constructor dependency injection that relies only on the supplied parameter type will continue to function as expected if using AOT; as well as in JIT mode if using the Angular CLI, `@ngtools/webpack` directly, or `tsickle`. Documentation for the `inject` function can be found at: https://angular.io/api/core/inject The decorator specification proposal can be found at: https://github.com/tc39/proposal-decorators
4069209
to
16468ff
Compare
PR has been updated to throw instead and now contains much less code. |
@clydin Is this still targeted for v16? Just checking in, since freeze is today. Happy to push on it or contributed in any way you need. |
This PR was merged into the repository by commit aad05eb. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Previously, attempting to turn off the
experimentalDecorators
TypeScript configuration option within an Angular project would result in build time errors. These errors were due to an exposed Decorator signature from@angular/core
that TypeScript thought was incompatible with standard decorators. However, Angular's class decorators (Component
,Directive
,Pipe
,Injectable
,NgModule
) are actually already compatible with standard decorators. The export types for the decorators only needed to be updated to reflect that compatibility. With the updated exported types, applications will now successfully compile and execute in AOT mode with one important dependency injection caveat explained in the note below.For JIT mode applications that are built with the Angular CLI,
@ngtools/webpack
, or usetsickle
, there were also no additional changes required with the same dependency injection caveat. These tools automatically convert property decorators (now called field decorators) at build time to store Angular property metadata directly on the relevant class. Building with these tools is the overwhelmingly common method of building an application. Any applications that do not use one of these tools will not function at runtime in JIT mode if using standard decorators. The behavior and code for when experimental decorators is enabled has been left intact.NOTE: Angular constructor dependency injection that requires parameter decorators is not supported. The standard decorator specification does not support parameter decorators. The
inject
function must be used for all cases that previously required a parameter decorator. This includes such decorators asInject
,Optional
,Self
,SkipSelf
,Host
, andAttribute
. Constructor dependency injection that relies only on the supplied parameter type will continue to function as expected if using AOT; as well as in JIT mode if using the Angular CLI,@ngtools/webpack
directly, ortsickle
.Does this PR introduce a breaking change?
Other information
Documentation for the
inject
function can be found at: https://angular.io/api/core/injectThe decorator specification proposal can be found at: https://github.com/tc39/proposal-decorators
An initial CLI E2E test that uses these changes is available here: angular/angular-cli#24886