-
Notifications
You must be signed in to change notification settings - Fork 26.5k
refactor(router): Adjust type of parameter in navigateByUrl and creat… #38227
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
Conversation
0059cc5
to
d7b67d5
Compare
This will need a migration to ensure call locations that violate the new type restriction do not break builds. The simplest way to do this would be to add |
Any update/help/info on what could be done on this PR or what we are waiting for? Been following this nagging issue for years :) |
Hi @bradtaniguchi, the change needs to land in a major version release since it's breaking. Once we have a branch that's accepting changes for v11, we can start looking at some of these updates and determining how to move them forward. We have several of them lined up and they're generally labelled with |
…teUrlTree with invalid parameters In angular#38227 the signatures of `navigateByUrl` and `createUrlTree` were updated to exclude unsupported properties from their `extras` parameter. This migration looks for the relevant method calls that pass in an `extras` parameter and drops the unsupported properties. **Before:** ``` this._router.navigateByUrl('/', {skipLocationChange: false, fragment: 'foo'}); ``` **After:** ``` this._router.navigateByUrl('/', { /* Removed unsupported properties by Angular migration: fragment. */ skipLocationChange: false }); ``` These changes also move the method call detection logic out of the `Renderer2` migration and into a common place so that it can be reused in other migrations.
…teUrlTree with invalid parameters (#38825) In #38227 the signatures of `navigateByUrl` and `createUrlTree` were updated to exclude unsupported properties from their `extras` parameter. This migration looks for the relevant method calls that pass in an `extras` parameter and drops the unsupported properties. **Before:** ``` this._router.navigateByUrl('/', {skipLocationChange: false, fragment: 'foo'}); ``` **After:** ``` this._router.navigateByUrl('/', { /* Removed unsupported properties by Angular migration: fragment. */ skipLocationChange: false }); ``` These changes also move the method call detection logic out of the `Renderer2` migration and into a common place so that it can be reused in other migrations. PR Close #38825
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
c3b2b92
to
d3d5937
Compare
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.
I like the new interfaces. CI doesn't :- Also the commit message needs tweaking.
f596f43
to
8f158ff
Compare
…eUrlTree to be more accurate `router.navigateByUrl` and `router.createUrlTree` only use a subset of the `NavigationExtras`. This commit changes the parameter type to use new interfaces that only specify the properties used by those function implementations. `NavigationExtras` extends both of those interfaces. Fixes angular#18798 BREAKING CHANGE: While the new parameter types allow a variable of type `NavigationExtras` to be passed in, they will not allow object literals, as they may only specify known properties. They will also not accept types that do not have properties in common with the ones in the `Pick`. To fix this error, only specify properties from the `NavigationExtras` which are actually used in the respective function calls or use a type assertion on the object or variable: `as NavigationExtras`.
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
You can preview 36a94e5 at https://pr38227-36a94e5.ngbuilds.io/. |
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: docs-packaging-and-releasing
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.
New interfaces look great 👍
Reviewed-for: public-api
Internal migration completed. presubmit (trigger global later as well) |
caretaker note: global presubmit showed a couple failures from this change. cl/333519736 will resolve those build failures. When syncing, either patch this CL in or wait for it to be submitted. |
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. |
…eUrlTree to be more accurate
router.navigateByUrl
androuter.createUrlTree
only use a subset of theNavigationExtras
. This commitchanges the parameter type to use new interfaces that only specify the properties used by
those function implementations.
NavigationExtras
extends both of those interfaces.Fixes #18798
BREAKING CHANGE: While the new parameter types allow a variable of type
NavigationExtras
to be passed in, they will not allow object literals,as they may only specify known properties. They will also not accept
types that do not have properties in common with the ones in the
Pick
.To fix this error, only specify properties from the
NavigationExtras
which areactually used in the respective function calls.