This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
fix: update typing of differ objects to fit the new contract of TrackByFunction #862
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously
DefaultIterableDiffer
was able to infer the type of it's generic by reading the type contract in the user defined trackBy function. This was becauseTrackByFunction
can be specified with a generic that is used to type its second argument. If this generic is not provided, like in this case, typescript infers this type from the function contract directly. Here it inferred typeFlatNode
. This inference is then used by the constructor ofDefaultIterableDiffer
, which is why we were not seeing this error previously.A change in the framework made it so the second argument of
TrackByFunction
is typed as a generic that extends the generic passed intoTrackByFunction
. Since we had not previously passed in this generic toTrackByFunction
, this type was inferred as an extension ofunknown
, causing a type error when passed as an argument to theDefaultIterableDiffer
constructor.Now the functions being used are typed directly as
TrackByFunction<FlatNode>
For clarity, the
DefaultIterableDiffer
generic is now also typed asFlatNode
.See angular/angular#41995 for the framework change.