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

Check generic types when using ViewChild/ContentChild and through DI #43253

Open
samuelfernandez opened this issue Aug 25, 2021 · 10 comments
Open
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Milestone

Comments

@samuelfernandez
Copy link

Which @angular/* package(s) are relevant/releated to the feature request?

compiler

Description

Imagine we have a parent component NgxOptions<T> and a child NgxOption<T>, with the following definition:

@Component({ /*...*/ })
export class NgxOptions<T> {
  @Input() options: T[];
}

@Component({ /*...*/ })
export class NgxOption<T> {
  @Input() display: (option: T) => string;

  // Forced parent component to be of the same generic type
  constructor(options: NgxOptions<T>) { }
}
<ngx-options [options]="options">
   <!-- I'd expect the compiler and language service to enforce both components have the same generic type -->
   <ngx-option [display]="displayOption"></ngx-option>
</ngx-options>

Proposed solution

It would be great to enforce type checking of components with a generic type when there is a relationship between them, such as ViewChild/ContentChild or injection

Alternatives considered

Right now the strict checking only applied to templates. However, it is only implemented for inputs/outputs, not for generic types in components when they are related.

@alxhub alxhub added area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking labels Aug 25, 2021
@ngbot ngbot bot modified the milestone: needsTriage Aug 25, 2021
@alxhub alxhub added the feature Issue that requests a new feature label Sep 2, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Sep 2, 2021
@angular-robot
Copy link
Contributor

angular-robot bot commented Sep 3, 2021

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Sep 3, 2021
@angular-robot
Copy link
Contributor

angular-robot bot commented Oct 13, 2021

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@angular-robot
Copy link
Contributor

angular-robot bot commented Nov 19, 2021

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors and removed feature: votes required Feature request which is currently still in the voting phase labels Nov 19, 2021
@Harpush
Copy link

Harpush commented Dec 30, 2021

This will be awesome! Correct me if I am wrong but that will allow typing context variables on content child template too. A very much needed feature

@alxhub alxhub removed the feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors label Feb 1, 2022
@alxhub alxhub added this to Inbox in Feature Requests via automation Feb 1, 2022
@alxhub alxhub moved this from Inbox to Needs Project Proposal in Feature Requests Feb 1, 2022
@alxhub
Copy link
Member

alxhub commented Feb 1, 2022

This has always been on the list for template type-checking.

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Feb 1, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 1, 2022

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors and removed feature: votes required Feature request which is currently still in the voting phase labels Feb 1, 2022
@alxhub alxhub added feature: under consideration Feature request for which voting has completed and the request is now under consideration and removed feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors labels Jun 6, 2022
@jessicajaniuk jessicajaniuk added feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors and removed feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors labels Jun 6, 2022
@samuelfernandez
Copy link
Author

This has always been on the list for template type-checking.

@alxhub Any update on this? I can try to submit a PR provided with some hints

@Harpush
Copy link

Harpush commented Mar 26, 2024

Can it be done with the new signal queries?

@samuelfernandez
Copy link
Author

Can it be done with the new signal queries?

The new API for signals does not add any changes regarding this issue, namely, strict typing in DI

@Harpush
Copy link

Harpush commented May 19, 2024

@alxhub Any news concerning this? I am really waiting for this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Projects
No open projects
Feature Requests
Needs Project Proposal
Development

No branches or pull requests

4 participants