Skip to content

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

Open

Description

@samuelfernandez

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.

Activity

  1. modified the milestone: needsTriage on Aug 25, 2021
  2. added
    featureLabel used to distinguish feature request from other issues
    on Sep 2, 2021
  3. modified the milestones: needsTriage, Backlog on Sep 2, 2021
  4. angular-robot commented on Sep 3, 2021

    @angular-robot
    Contributor

    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.

  5. angular-robot commented on Oct 13, 2021

    @angular-robot
    Contributor

    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.

  6. angular-robot commented on Nov 19, 2021

    @angular-robot
    Contributor

    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.

  7. Harpush commented on Dec 30, 2021

    @Harpush

    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

  8. alxhub commented on Feb 1, 2022

    @alxhub
    Member

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

  9. angular-robot commented on Feb 1, 2022

    @angular-robot
    Contributor

    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.

  10. added
    feature: under considerationFeature request for which voting has completed and the request is now under consideration
    and removed on Jun 6, 2022
  11. samuelfernandez commented on Dec 26, 2022

    @samuelfernandez
    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

  12. Harpush commented on Mar 26, 2024

    @Harpush

    Can it be done with the new signal queries?

  13. samuelfernandez commented on Mar 26, 2024

    @samuelfernandez
    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

  14. Harpush commented on May 19, 2024

    @Harpush

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compilerIssues related to `ngc`, Angular's template compilercompiler: template type-checkingfeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions