-
Notifications
You must be signed in to change notification settings - Fork 26.3k
fix(compiler-cli): disallow compiling with the emitDeclarationOnly
TS compiler option enabled
#61609
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
base: main
Are you sure you want to change the base?
fix(compiler-cli): disallow compiling with the emitDeclarationOnly
TS compiler option enabled
#61609
Conversation
Question for reviewers: Should this be labelled as a breaking change given that this is mostly broken already anyway and only happens to work by chance in a few cases? |
Could we make this work by mimicking the behavior? Potentially by turning off the option if enabled for the underlying Typescript compilation and then filtering the output files? Not ideal from a performance standpoint but may give correct results at least. |
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.
LGTM from the code perspective, I'm going to add someone who understands the context
|
…TS compiler option enabled Running the Angular compiler with declaration-only emission is dangerous because Angular does not yet support this mode as it relies on the Ivy compilation which does not run in this mode In the best case, everything works fine as incidentally there's no difference in the emitted type declarations (e.g. this is the case for TS files containing no Angular annotations or only `@Injectable` annotations). In the worst case, compilation silently fails in that the compilation succeeds but the resulting type declarations are missing the Angular type information and are therefore incomplete. This happens for all components, directives and modules. BREAKING CHANGE: The Angular compiler now produces an error when the the `emitDeclarationOnly` TS compiler option is enabled as this mode is not supported.
5353cf7
to
46c2fcf
Compare
TL;DR: This PR is good to merge as is, since compilation is currently broken whenever the More details: There are three boolean TS compiler options relevant for type declaration (DTS) emission:
Before PR #61334, only the declaration transforms were added to the angular/packages/compiler-cli/src/ngtsc/core/src/compiler.ts Lines 819 to 832 in 68d774f
angular/packages/compiler-cli/src/ngtsc/core/src/compiler.ts Lines 867 to 890 in 68d774f
However, the declaration transforms rely on the Ivy compilation transforms to run before them, but the TS compiler only runs the This leads to the following situation considering the state of the three TS compiler options:
Therefore, it actually does make sense to disallow compiling with the That being said, there is some opportunity to improve on the situation in a follow-up: PR #61334 introduced experimental support for fast type declaration emission, which is the last row of the table above where all three TS options are enabled. However, the implementation somewhat conflates the last two rows of the table by only looking at the When in fast declaration emission mode, the implementation does two things:
These two things could be decoupled by adding the |
Since it appears possible to correctly emit the type declarations, I think it would be useful long-term to fix the option if possible rather than issuing an error. |
Type information should still be available with the |
Note: public API review isn't necessary here as this is just a new error code and it seems fine. |
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?
Running the Angular compiler with declaration-only emission is dangerous because Angular does not yet support this mode as it relies on the Ivy compilation which does not run in this mode.
In the best case, everything works fine as incidentally there's no difference in the emitted type declarations (e.g. this is the case for TS files containing no Angular annotations or only
@Injectable
annotations).In the worst case, compilation silently fails in that the compilation succeeds but the resulting type declarations are missing the Angular type information and are therefore incomplete. This happens for all components, directives and modules.
Example case of a silent failure:
Expected emitted type declarations:
Actual emitted type declarations:
What is the new behavior?
The Angular compiler now produces an error when the the
emitDeclarationOnly
TS compiler option is enabled.Does this PR introduce a breaking change?
Projects will have to disable the
emitDeclarationOnly
TS compiler option when compiling with Angular.