New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): Allow passing AbstractType to the inject function #37958
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Reviewed-for: public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed-for: public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mitchellwills, thanks for creating this PR 👍
I did a quick search in Angular codebase and found a couple more places where the AbstractType
is not included (both in the current state of the codebase and in your PR):
- https://github.com/angular/angular/blob/master/packages/core/src/di/injector.ts#L157
- https://github.com/angular/angular/blob/master/packages/core/src/di/r3_injector.ts#L183
- https://github.com/angular/angular/blob/master/packages/core/src/di/r3_injector.ts#L406
- https://github.com/angular/angular/blob/master/packages/core/src/render3/component_ref.ts#L85
- https://github.com/angular/angular/blob/master/packages/core/src/render3/interfaces/injector.ts#L137
- https://github.com/angular/angular/blob/master/packages/core/src/render3/interfaces/injector.ts#L241
- https://github.com/angular/angular/blob/master/packages/examples/core/di/ts/injector_spec.ts#L15
Could you please have a quick look to see if these places also require type change?
Potentially Type|InjectionToken|AbstractType should become a type alias, but i'm not sure what it should be called.
I really like this idea, could you please create a new ticket (feature request) to capture this proposal?
Thank you.
@googlebot ping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed-for: public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed-for: public-api
LGTM with one suggestion
export function ɵɵinject<T>(token: Type<T>|InjectionToken<T>): T; | ||
export function ɵɵinject<T>(token: Type<T>|InjectionToken<T>, flags?: InjectFlags): T|null; | ||
export function ɵɵinject<T>(token: Type<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null { | ||
export function ɵɵinject<T>(token: Type<T>|InjectionToken<T>|AbstractType<T>): T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a nitpick, but I would suggest reordering AbstractType
and InjectionToken
:
export function ɵɵinject<T>(token: Type<T>|InjectionToken<T>|AbstractType<T>): T; | |
export function ɵɵinject<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>): T; |
as they're two sides of the same coin, vs InjectionToken
which is more of a foreign currency ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding approval for fw-core
@mitchellwills - are you still interested in working on this PR? If so, could you rebase and deal with the comments? Thanks! |
yah, sorry for the delay (I worked around it so this dropped in priority for me). I'll rebase and address the comments next week |
FYI, related ticket: #23611. |
This is a type only change that replaces `Type<T>|InjectionToken<T>` with `Type<T>|AbstractType<T>|InjectionToken<T>` in the injector.
74a1fc5
to
c80fe19
Compare
I think i've addressed the comments from above: rebase, additional replacements, reorder to I also filed #39792 |
FYI, global presubmit indicated no problems related to this change, so I'm adding it to the merge queue. Note: I've changed the target from "patch" to "minor" though since this PR can also be considered as a feature (that more types are now allowed in the inject function). |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This is a type only change that replaces
Type<T>|InjectionToken<T>
withType<T>|AbstractType<T>|InjectionToken<T>
in the injector.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
inject
instruction does not acceptAbstractType
as a token.Issue Number: N/A
What is the new behavior?
inject
instruction acceptsAbstractType
as a token. This is a type only change (should have no runtime impact)Does this PR introduce a breaking change?
Other information
Potentially
Type<T>|AbstractType<T>|InjectionToken<T>
should become a type alias, but i'm not sure what it should be called.