8000 Check generic types when using `ViewChild`/`ContentChild` and through DI · Issue #43253 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content
Check generic types when using ViewChild/ContentChild and through DI #43253
Open
< 8233 div class="Box-sc-g0xbh4-0 gRssIw">@samuelfernandez

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compilerIssues related to `ngc`, Angular's template compilercompiler: template type-checkingfeatureIssue that requests a new featurefeature: 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

      0