Using fullTemplateTypeCheck produces error in template when using generic variable

I have the following line in the template of an angular component

<tr dt-row-placeholder [contents]="dtElements" [context]="datum" *ngFor="let datum of model.Collection"></tr>

when I hover over the variables in VS code I see enter image description here and enter image description here

however, i get the following error on build

Error: src/sp-data-table/data-table-body/data-table-body.component.html:27:55 - error TS2322: Type 'any' is not assignable to type 'never'.
    27       <tr dt-row-placeholder [contents]="dtElements" [context]="datum" *ngFor="let datum of model.Collection"></tr>

enter image description here

I’m wondering if there is anything I can do to resolve this while leaving fullTemplateTypeCheck enabled. Setting fullTemplateTypeCheck to false fixes the issue but means I’m losing out on the benefits it provides in other parts of the app.

My hunch is that, although "context" and "datum" appear as type "T" in the hover, typescript has no way of knowing that the T of "DataTableRowPlaceholderComponent" is the same T as "datum" which is an element of a T[] defined on a property of the containing component. I guess my question is, is there any way for me to tell angular that the two "T"s refer to the same type? It is curious to me that the error seems to indicate that "context" is of type "never" and "datum" is of type "any" when the intellisense hover somehow knows they are not those types.

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.