-
Notifications
You must be signed in to change notification settings - Fork 25.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(compiler): add support for compile-time required inputs #49304
Conversation
a01da1b
to
758f88f
Compare
How will it affect |
Note for reviewer: the |
758f88f
to
5faa1ab
Compare
packages/compiler-cli/src/ngtsc/annotations/directive/src/shared.ts
Outdated
Show resolved
Hide resolved
As described by @nartc in this tweet (https://twitter.com/Nartc1410/status/1631694281298640896?s=20) enforcing the exposure of required inputs of host directives might be a little bit too rigid concerning the reusability of a directive. Maybe the configuration object of host directives can be augmented with a property specifying whether the exposure of required inputs should be enforced. For example |
5faa1ab
to
1117de3
Compare
Based on the discussion in angular#49304 (comment). Reworks how inputs are stored throughout the compiler to allow for required information to be stored alongside them. The refactor introduces a new `ClassInputPropertyMapping` class which is similar to the existing `ClassPropertyMapping`, but with the ability to store additional information about the mapping which may be handy for future features as well.
Based on the discussion in angular#49304 (comment). Reworks how inputs are stored throughout the compiler to allow for required information to be stored alongside them. The refactor introduces a new `ClassInputPropertyMapping` class which is similar to the existing `ClassPropertyMapping`, but with the ability to store additional information about the mapping which may be handy for future features as well.
Based on the discussion in angular#49304 (comment). Reworks how inputs are stored throughout the compiler to allow for required information to be stored alongside them. The refactor introduces a new `ClassInputPropertyMapping` class which is similar to the existing `ClassPropertyMapping`, but with the ability to store additional information about the mapping which may be handy for future features as well.
Based on the discussion in angular#49304 (comment). Reworks how inputs are stored throughout the compiler to allow for required information to be stored alongside them. The refactor introduces a new `ClassInputPropertyMapping` class which is similar to the existing `ClassPropertyMapping`, but with the ability to store additional information about the mapping which may be handy for future features as well.
Based on the discussion in angular#49304 (comment). Reworks how inputs are stored throughout the compiler to allow for required information to be stored alongside them. The refactor introduces a new `ClassInputPropertyMapping` class which is similar to the existing `ClassPropertyMapping`, but with the ability to store additional information about the mapping which may be handy for future features as well.
Based on the discussion in angular#49304 (comment). Reworks how inputs are stored throughout the compiler to allow for required information to be stored alongside them. The refactor introduces a new `ClassInputPropertyMapping` class which is similar to the existing `ClassPropertyMapping`, but with the ability to store additional information about the mapping which may be handy for future features as well.
Based on the discussion in angular#49304 (comment). Reworks the compiler internals to allow for additional information about inputs to be stored. This is a prerequisite for required inputs.
Based on the discussion in #49304 (comment). Reworks the compiler internals to allow for additional information about inputs to be stored. This is a prerequisite for required inputs. PR Close #49333
4667917
to
dfc59a9
Compare
I've integrated the changes from #49333 and addressed the remaining feedback. |
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.
dfc59a9
to
8d0da53
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: 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.
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.
reviewed-for: public-api
Carertaker note: one target is failing internally. It doesn't look related to this change. |
This PR was merged into the repository by commit 1a6ca68. |
…ngular#49304)" This reverts commit 1a6ca68. This breaks tests in google3 which might be depending on private APIs. We need to update these tests before we can land this PR.
Are you sure it's merged into 16.0.0-next.3?
|
it was reverted for some internal issues
pt., 17 mar 2023 o 12:15 Evgeniy OZ ***@***.***> napisał(a):
… Are you sure it's merged into 16.0.0-next.3?
I can't find it in 16.0.0-next.3. When I use @input
<https://github.com/input>({required: true}) in a directive or a
component:
error TS2345: Argument of type '{ required: boolean; }' is not assignable to parameter of type 'string'.
—
Reply to this email directly, view it on GitHub
<#49304 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFKBQQNMNGZJ4BVTGIFY76TW4RBWNANCNFSM6AAAAAAVOJMFJU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
thanks @kbrilla |
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. |
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:
required: true
property to theInput
decorator or into theinputs
array.OutOfBandDiagnosticRecorder
, rather than generating a new structure in the TCB, because it allows us to provide a better error message.Fixes #37706.