fix(core): allow proper type inference when ngFor is used with a trackBy function (#42692)

In #41995 the type of `TrackByFunction` was changed such that the
declaration of a `trackBy` function did not cause the item type to be
widened to the `trackBy`'s item type, which may be a supertype of the
iterated type. This has introduced situations where the template type
checker is now reporting errors for cases where a `trackBy` function is
no longer assignable to `TrackByFunction`.

This commit fixes the error by also including the item type `T` in
addition to the constrained type parameter `U`, allowing TypeScript to
infer an appropriate `T`.

Fixes #42609

PR Close #42692
This commit is contained in:
JoostK
2021-06-28 21:35:03 +02:00
committed by Andrew Kushnir
parent 970d7f7c6f
commit 51156f3f07
4 changed files with 75 additions and 3 deletions
@@ -116,5 +116,5 @@ export interface OnDestroy {
}
export interface TrackByFunction<T> {
<U extends T>(index: number, item: U): any;
<U extends T>(index: number, item: T&U): any;
}