feat(compiler): add support for compile-time required inputs#49304
feat(compiler): add support for compile-time required inputs#49304crisbeto wants to merge 1 commit intoangular:mainfrom
Conversation
a01da1b to
758f88f
Compare
|
How will it affect |
|
Note for reviewer: the |
758f88f to
5faa1ab
Compare
packages/compiler-cli/src/ngtsc/annotations/common/src/diagnostics.ts
Outdated
Show resolved
Hide resolved
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 |
packages/compiler-cli/src/ngtsc/typecheck/test/diagnostics_spec.ts
Outdated
Show resolved
Hide resolved
5faa1ab to
1117de3
Compare
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
AndrewKushnir
left a comment
There was a problem hiding this comment.
Reviewed-for: public-api
jessicajaniuk
left a comment
There was a problem hiding this comment.
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: trueproperty to theInputdecorator or into theinputsarray.OutOfBandDiagnosticRecorder, rather than generating a new structure in the TCB, because it allows us to provide a better error message.Fixes #37706.