Skip to content
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

Merged
merged 1 commit into from
Jun 22, 2021

Conversation

AleksanderBodurri
Copy link
Contributor

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 because TrackByFunction 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 type FlatNode. This inference is then used by the constructor of DefaultIterableDiffer, 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 into TrackByFunction. Since we had not previously passed in this generic to TrackByFunction, this type was inferred as an extension of unknown, causing a type error when passed as an argument to the DefaultIterableDiffer constructor.

Now the functions being used are typed directly as TrackByFunction<FlatNode>

For clarity, the DefaultIterableDiffer generic is now also typed as FlatNode.

See angular/angular#41995 for the framework change.

…ByFunction

Previously `DefaultIterableDiffer` was able to infer the type of it's generic by reading the type contract defined by the user defined trackBy function. This was because `TrackByFunction` 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. In this case this inferred type was `FlatNode`. This inference is then propagated to `DefaultIterableDiffer`, 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 into `TrackByFunction`. Since we had not previously passed in this generic to `TrackByFunction`, this type was inferred as an extension of `unknown`, causing a type error when passed as an argument to the `DefaultIterableDiffer` constructor.

Now the functions being used are typed directly as `TrackByFunction<FlatNode>`

For clarity, the `DefaultIterableDiffer` generic is now also typed as `FlatNode`.

See angular/angular#41995 for the framework change.
@mgechev mgechev merged commit c165ea7 into main Jun 22, 2021
@mgechev mgechev deleted the differ-contract-fix branch June 22, 2021 00:56
AleksanderBodurri added a commit to AleksanderBodurri/angular-devtools that referenced this pull request Sep 16, 2021
…ByFunction (rangle#862)

Previously `DefaultIterableDiffer` was able to infer the type of it's generic by reading the type contract defined by the user defined trackBy function. This was because `TrackByFunction` 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. In this case this inferred type was `FlatNode`. This inference is then propagated to `DefaultIterableDiffer`, 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 into `TrackByFunction`. Since we had not previously passed in this generic to `TrackByFunction`, this type was inferred as an extension of `unknown`, causing a type error when passed as an argument to the `DefaultIterableDiffer` constructor.

Now the functions being used are typed directly as `TrackByFunction<FlatNode>`

For clarity, the `DefaultIterableDiffer` generic is now also typed as `FlatNode`.

See angular/angular#41995 for the framework change.
AleksanderBodurri added a commit to AleksanderBodurri/angular-devtools that referenced this pull request Sep 27, 2021
…t of TrackByFunction (rangle#862)

Previously `DefaultIterableDiffer` was able to infer the type of it's generic by reading the type contract defined by the user defined trackBy function. This was because `TrackByFunction` 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. In this case this inferred type was `FlatNode`. This inference is then propagated to `DefaultIterableDiffer`, 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 into `TrackByFunction`. Since we had not previously passed in this generic to `TrackByFunction`, this type was inferred as an extension of `unknown`, causing a type error when passed as an argument to the `DefaultIterableDiffer` constructor.

Now the functions being used are typed directly as `TrackByFunction<FlatNode>`

For clarity, the `DefaultIterableDiffer` generic is now also typed as `FlatNode`.

See angular/angular#41995 for the framework change.
AleksanderBodurri added a commit to AleksanderBodurri/angular-devtools that referenced this pull request Oct 27, 2021
…ByFunction (rangle#862)

Previously `DefaultIterableDiffer` was able to infer the type of it's generic by reading the type contract defined by the user defined trackBy function. This was because `TrackByFunction` 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. In this case this inferred type was `FlatNode`. This inference is then propagated to `DefaultIterableDiffer`, 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 into `TrackByFunction`. Since we had not previously passed in this generic to `TrackByFunction`, this type was inferred as an extension of `unknown`, causing a type error when passed as an argument to the `DefaultIterableDiffer` constructor.

Now the functions being used are typed directly as `TrackByFunction<FlatNode>`

For clarity, the `DefaultIterableDiffer` generic is now also typed as `FlatNode`.

See angular/angular#41995 for the framework change.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants