Check generic types when using `ViewChild`/`ContentChild` and through DI
See original GitHub issueWhich @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.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:6 (5 by maintainers)
Top Results From Across the Web
ViewChildren & ContentChildren • Angular - codecraft.tv
We can solve that by using the alternative @ViewChildren decorator along side the QueryList generic type. TypeScript. Copy import { ViewChildren, QueryList } ......
Read more >Static query migration guide - Angular
In preparation for this change, in version 8, we are migrating all applications and libraries to explicitly specify the resolution strategy for @ViewChild...
Read more >changing ViewChild implementation to support multiple ...
I wish to refactor this to work for a list of generic components. I changed my HTML to: <div *ngFor="let row of Page.Rows"...
Read more >Here is what you need to know about dynamic components in ...
We start with the comparison of dynamic components functionality in Angular and AngularJS and then continue with main concepts that enable dynamic ...
Read more >Navigate the component tree with DI - Angular
Check out Query , QueryList , ViewChildren , and ContentChildren in the API ... You use standard class injection to acquire a parent...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This has always been on the list for template type-checking.
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