Repository navigation
Conversation
JeanMeche
force-pushed
the
fix/53894-inject-generic-type
branch
4 times, most recently
from
November 2, 2026 01:52
765149b to
169e53d
Compare
JeanMeche
force-pushed
the
fix/53894-inject-generic-type
branch
12 times, most recently
from
November 2, 2026 10:53
547fe92 to
de1fc86
Compare
Member
Author
Type Inference SummaryUsing
|
JeanMeche
added a commit
to JeanMeche/angular
that referenced
this pull request
Nov 2, 2026
…ecting or querying tokens Ports the test changes from angular#71762.
JeanMeche
force-pushed
the
fix/53894-inject-generic-type
branch
from
November 2, 2026 20:10
de1fc86 to
469230d
Compare
Contributor
|
As a question, could this be considered a breaking change? or at least I think we might need a migration script after this is merged, since I've seen code like this many times in codebases private readonly dataService: DataService<MyItem> = inject(DataService); |
Member
Author
|
It's definitely a breaking change. It's a large breakage inside Google3. If we agree to land it. It will probably be a 2-stepper. (the 2nd step being the actual breaking change during the v23 window + a migration script alongside it). |
JeanMeche
force-pushed
the
fix/53894-inject-generic-type
branch
from
November 3, 2026 17:43
469230d to
789887a
Compare
JeanMeche
force-pushed
the
fix/53894-inject-generic-type
branch
2 times, most recently
from
November 3, 2026 18:14
e772785 to
6de5e46
Compare
JeanMeche
force-pushed
the
fix/53894-inject-generic-type
branch
5 times, most recently
from
November 3, 2026 22:06
c7beaf5 to
454585c
Compare
…g tokens
In TypeScript, instantiation expressions on class constructors specialize construct signatures (`new`), leaving the `prototype` property unspecialized. Because `ProviderToken<T>` includes `AbstractType<T>` (`{ prototype: T }`), passing specialized tokens to `inject()` or signal queries caused TypeScript to infer `T` from `prototype`, widening the return type.
To preserve type parameters:
- Added `inject<T = any>(token: abstract new (...args: any[]) => T): T;` overload.
- Added `abstract new (...args: any[]) => ReadT` and `InjectionToken<ReadT>` overloads for query `read` options.
- Added `abstract new (...args: any[]) => LocatorT` overloads for query locators.
Fixes angular#53894
Fixes angular#48126
JeanMeche
force-pushed
the
fix/53894-inject-generic-type
branch
from
November 3, 2026 22:40
454585c to
704d1bd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In TypeScript, instantiation expressions on class constructors specialize construct signatures (
new), leaving theprototypeproperty unspecialized. BecauseProviderToken<T>includesAbstractType<T>({ prototype: T }), passing specialized tokens toinject()or signal queries caused TypeScript to inferTfromprototype, widening the return type.To preserve type parameters:
inject<T = any>(token: abstract new (...args: any[]) => T): T;overload.abstract new (...args: any[]) => ReadTandInjectionToken<ReadT>overloads for queryreadoptions.abstract new (...args: any[]) => LocatorToverloads for query locators.Fixes #53894
Fixes #48126