Skip to content
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

Marking @Input as required, again #37706

Open
thw0rted opened this issue Jun 24, 2020 · 1 comment
Open

Marking @Input as required, again #37706

thw0rted opened this issue Jun 24, 2020 · 1 comment

Comments

@thw0rted
Copy link

@thw0rted thw0rted commented Jun 24, 2020

🚀 feature request

Relevant Package

This feature request is for @angular/core

Description

There is a long history of discussion about whether / how to have the compiler enforce that specific inputs are provided to components: #11904 #18156 #24879 #28403 #30974

However, all of those are now closed and locked. They contain some advice about how to mitigate the problem, or kick the can down the road ("One day I hope we'll be able to do this. That day is not today."), but thanks to the lock-bot none of them can be used to continue the conversation, so I guess we need yet another issue, because I believe the problem still exists.

Describe the solution you'd like

It should be possible to annotate inputs such that using a component in a template without providing a value for that input is a compile-time error. Template checking has come a long way, and it's already possible for the compiler to flag providing the wrong type as an argument. Combine with the strictPropertyInitializers flag, and such a check could rely on the existing ! assertion operator.

Describe alternatives you've considered

The best approach I've seen while reviewing the above issues is specifying the required attributes in the selector component metadata, but a) apparently that won't catch passing null or undefined to an Input that not defined with a type that includes those values, and b) that appears to break certain test harnesses? Also, I haven't started using strictTemplates / fullTemplateTypeCheck yet due to some problems in previous versions with narrowing on *ngIf that may or may not have been resolved -- those existing capabilities may address some or all of this need.

@cyrilletuzi
Copy link
Contributor

@cyrilletuzi cyrilletuzi commented Jun 25, 2020

Combine with the strictPropertyInitializers flag, and such a check could rely on the existing ! assertion operator.

For information, it is what Ionic's Stencil is doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.