Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uprefactor(router): Adjust type of parameter in navigateByUrl and creat… #38227
Conversation
0059cc5
to
d7b67d5
|
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 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 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
|
LGTM |
|
I agree with @petebacondarwin that named interfaces are more ergonomic here. Something like (is there some context for why the original type is "extras" and not "options"?) |
|
@petebacondarwin @jelbourn - I've updated the PR to introduce new interfaces. PTAL.
Likely no technical reason. The router module also has an argument type called |
c3b2b92
to
d3d5937
|
I like the new interfaces. CI doesn't :- Also the commit message needs tweaking. |
f596f43
to
8f158ff
…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 #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`.
|
LGTM Reviewed-for: public-api |
|
You can preview 36a94e5 at https://pr38227-36a94e5.ngbuilds.io/. |
|
LGTM Reviewed-for: docs-packaging-and-releasing |
|
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. |


…eUrlTree to be more accurate
router.navigateByUrlandrouter.createUrlTreeonly use a subset of theNavigationExtras. This commitchanges the parameter type to use new interfaces that only specify the properties used by
those function implementations.
NavigationExtrasextends both of those interfaces.Fixes #18798
BREAKING CHANGE: While the new parameter types allow a variable of type
NavigationExtrasto 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
NavigationExtraswhich areactually used in the respective function calls.