-
Notifications
You must be signed in to change notification settings - Fork 27k
Inject migration follow-up fixes #57127
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
Closed
Closed
Conversation
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
Adds a shorter alias to the inject migration.
…rence Currently if an injected type has type arguments, we copy it over together with the type arguments to inject, because `inject()` isn't able to infer the generic properly otherwise. E.g. if there's `constructor(el: ElementRef<HTMLElement>)` we produce `inject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);`. These changes drop the generics from the `inject()` parameter since we're overwriting the type anyway. The example from above would become `inject<ElementRef<HTMLElement>>(ElementRef);`.
This can up in Material where we had a `constructor(@optionA() foo: Foo | null)` which ended up producing incorrect code, because the union type was preserved. These changes resolve the issue by picking out the first non-literal type from the union for the `inject` call.
Updates the inject migration to unwrap the `forwardRef` call in cases like `constructor(@Inject(forwardRef(() => Foo)) foo: Foo);`, because the `forwardRef` will type the initializer to `any` and it shouldn't be necessary.
devversion
approved these changes
Jul 25, 2024
Contributor
|
This PR was merged into the repository by commit aae9646. The changes were merged into the following branches: main |
dylhunn
pushed a commit
that referenced
this pull request
Jul 26, 2024
…rence (#57127) Currently if an injected type has type arguments, we copy it over together with the type arguments to inject, because `inject()` isn't able to infer the generic properly otherwise. E.g. if there's `constructor(el: ElementRef<HTMLElement>)` we produce `inject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);`. These changes drop the generics from the `inject()` parameter since we're overwriting the type anyway. The example from above would become `inject<ElementRef<HTMLElement>>(ElementRef);`. PR Close #57127
dylhunn
pushed a commit
that referenced
this pull request
Jul 26, 2024
vladboisa
pushed a commit
to vladboisa/angular
that referenced
this pull request
Jul 29, 2024
Adds a shorter alias to the inject migration. PR Close angular#57127
vladboisa
pushed a commit
to vladboisa/angular
that referenced
this pull request
Jul 29, 2024
…rence (angular#57127) Currently if an injected type has type arguments, we copy it over together with the type arguments to inject, because `inject()` isn't able to infer the generic properly otherwise. E.g. if there's `constructor(el: ElementRef<HTMLElement>)` we produce `inject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);`. These changes drop the generics from the `inject()` parameter since we're overwriting the type anyway. The example from above would become `inject<ElementRef<HTMLElement>>(ElementRef);`. PR Close angular#57127
vladboisa
pushed a commit
to vladboisa/angular
that referenced
this pull request
Jul 29, 2024
This can up in Material where we had a `constructor(@optionA() foo: Foo | null)` which ended up producing incorrect code, because the union type was preserved. These changes resolve the issue by picking out the first non-literal type from the union for the `inject` call. PR Close angular#57127
vladboisa
pushed a commit
to vladboisa/angular
that referenced
this pull request
Jul 29, 2024
Updates the inject migration to unwrap the `forwardRef` call in cases like `constructor(@Inject(forwardRef(() => Foo)) foo: Foo);`, because the `forwardRef` will type the initializer to `any` and it shouldn't be necessary. PR Close angular#57127
|
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
action: merge
The PR is ready for merge by the caretaker
area: migrations
Issues related to `ng update`/`ng generate` migrations
target: minor
This PR is targeted for the next minor release
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.
Includes the following fixes that came up as a result of running the
injectmigration against Material and the CDK.fix(migrations): add alias to inject migration
Adds a shorter alias to the inject migration.
fix(migrations): remove generic arguments from the injected type reference
Currently if an injected type has type arguments, we copy it over together with the type arguments to inject, because
inject()isn't able to infer the generic properly otherwise. E.g. if there'sconstructor(el: ElementRef<HTMLElement>)we produceinject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);.These changes drop the generics from the
inject()parameter since we're overwriting the type anyway. The example from above would becomeinject<ElementRef<HTMLElement>>(ElementRef);.fix(migrations): account for parameters with union types
This came up in Material where we had a
constructor(@Optional() foo: Foo | null)which ended up producing incorrect code, because the union type was preserved.These changes resolve the issue by picking out the first non-literal type from the union for the
injectcall.fix(migrations): unwrap injected forwardRef
Updates the inject migration to unwrap the
forwardRefcall in cases likeconstructor(@Inject(forwardRef(() => Foo)) foo: Foo);, because theforwardRefwill type the initializer toanyand it shouldn't be necessary.