Skip to content

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Mar 16, 2023

Note: this is a resubmit of #49304 which had to be rolled back temporarily due to an internal issue.

Adds support for marking a directive input as required. During template type checking, the compiler will verify that all required inputs have been specified and will raise a diagnostic if one or more are missing. Some specifics:

  • Inputs are marked as required by passing an object literal with a required: true property to the Input decorator or into the inputs array.
  • Required inputs imply that the directive can't work without them. This is why there's a new check that enforces that all required inputs of a host directive are exposed on the host.
  • Required input diagnostics are reported through the OutOfBandDiagnosticRecorder, rather than generating a new structure in the TCB, because it allows us to provide a better error message.
  • Currently required inputs are only supported during AOT compilation, because knowing which bindings are present during JIT can be tricky and may lead to increased bundle sizes.

Fixes #37706.

Adds support for marking a directive input as required. During template type checking, the compiler will verify that all required inputs have been specified and will raise a diagnostic if one or more are missing. Some specifics:
* Inputs are marked as required by passing an object literal with a `required: true` property to the `Input` decorator or into the `inputs` array.
* Required inputs imply that the directive can't work without them. This is why there's a new check that enforces that all required inputs of a host directive are exposed on the host.
* Required input diagnostics are reported through the `OutOfBandDiagnosticRecorder`, rather than generating a new structure in the TCB, because it allows us to provide a better error message.
* Currently required inputs are only supported during AOT compilation, because knowing which bindings are present during JIT can be tricky and may lead to increased bundle sizes.

Fixes angular#37706.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release area: compiler Issues related to `ngc`, Angular's template compiler labels Mar 16, 2023
@crisbeto crisbeto requested a review from alxhub March 16, 2023 20:27
@ngbot ngbot bot modified the milestone: Backlog Mar 16, 2023
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Mar 16, 2023
Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: global-approvers

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 16, 2023
@crisbeto crisbeto modified the milestones: Backlog, v16-candidates Mar 17, 2023
@pkozlowski-opensource
Copy link
Member

This PR was merged into the repository by commit 13dd614.

atscott added a commit to atscott/angular that referenced this pull request Mar 17, 2023
…ngular#49453)"

This reverts commit 13dd614.

This breaks a g3 Typescript compilation tests where diagnostics are
expected for a missing input in the component.
pkozlowski-opensource pushed a commit that referenced this pull request Mar 17, 2023
…49453)" (#49467)

This reverts commit 13dd614.

This breaks a g3 Typescript compilation tests where diagnostics are
expected for a missing input in the component.

PR Close #49467
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler detected: feature PR contains a feature commit target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Canonical: Marking @Input as required

3 participants