Visitar URL original
refactor(router): Adjust type of parameter in navigateByUrl and creat… by atscott · Pull Request #38227 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20201008114925/https://github.com/angular/angular/pull/38227
Skip to content
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

refactor(router): Adjust type of parameter in navigateByUrl and creat… #38227

Closed
wants to merge 1 commit into from

Conversation

@atscott
Copy link
Contributor

@atscott atscott commented Jul 24, 2020 •

…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.

@ngbot ngbot bot modified the milestone: needsTriage Jul 24, 2020
@googlebot googlebot added the cla: yes label Jul 24, 2020
@atscott atscott force-pushed the atscott:routeromit branch 2 times, most recently from 0059cc5 to d7b67d5 Jul 24, 2020
@atscott atscott modified the milestones: needsTriage, v11-candidates Jul 24, 2020
@atscott atscott force-pushed the atscott:routeromit branch from d7b67d5 to d4557da Jul 24, 2020
@atscott
Copy link
Contributor Author

@atscott atscott commented Jul 24, 2020

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 as {} on the parameter if the object specifies properties that are no longer allowed.

@bradtaniguchi
Copy link

@bradtaniguchi bradtaniguchi commented Aug 13, 2020

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 :)

@atscott
Copy link
Contributor Author

@atscott atscott commented Aug 13, 2020

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 cross-cutting: types.

crisbeto added a commit to crisbeto/angular that referenced this pull request Sep 12, 2020
…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.
crisbeto added a commit to crisbeto/angular that referenced this pull request Sep 12, 2020
…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.
crisbeto added a commit to crisbeto/angular that referenced this pull request Sep 12, 2020
…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.
AndrewKushnir added a commit that referenced this pull request Sep 16, 2020
…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
@atscott atscott requested a review from crisbeto Sep 17, 2020
@atscott atscott removed the state: blocked label Sep 17, 2020
@atscott atscott force-pushed the atscott:routeromit branch from d4557da to 4e6ed84 Sep 17, 2020
Copy link
Member

@crisbeto crisbeto left a comment

LGTM

@pullapprove pullapprove bot requested a review from AndrewKushnir Sep 17, 2020
Copy link
Member

@jelbourn jelbourn left a comment

I agree with @petebacondarwin that named interfaces are more ergonomic here. Something like NavigateByUrlExtras or NavigateByUrlOptions?

(is there some context for why the original type is "extras" and not "options"?)

@pullapprove pullapprove bot requested a review from jelbourn Sep 21, 2020
@atscott
Copy link
Contributor Author

@atscott atscott commented Sep 21, 2020

@petebacondarwin @jelbourn - I've updated the PR to introduce new interfaces. PTAL.

(is there some context for why the original type is "extras" and not "options"?)

Likely no technical reason. The router module also has an argument type called ExtraOptions, so my guess would be that Extras and Options were favored somewhat equally.

@atscott atscott force-pushed the atscott:routeromit branch 5 times, most recently from c3b2b92 to d3d5937 Sep 21, 2020
Copy link
Member

@petebacondarwin petebacondarwin left a comment

I like the new interfaces. CI doesn't :- Also the commit message needs tweaking.

@atscott atscott force-pushed the atscott:routeromit branch 2 times, most recently from f596f43 to 8f158ff Sep 22, 2020
…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`.
@atscott atscott force-pushed the atscott:routeromit branch from 8f158ff to 36a94e5 Sep 22, 2020
Copy link
Member

@jelbourn jelbourn left a comment

LGTM

Reviewed-for: public-api

@mary-poppins
Copy link

@mary-poppins mary-poppins commented Sep 22, 2020

Copy link
Member

@jelbourn jelbourn left a comment

LGTM

Reviewed-for: docs-packaging-and-releasing

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

New interfaces look great 👍

Reviewed-for: public-api

@atscott atscott removed the state: blocked label Sep 23, 2020
@atscott
Copy link
Contributor Author

@atscott atscott commented Sep 23, 2020

Internal migration completed. presubmit (trigger global later as well)

@atscott
Copy link
Contributor Author

@atscott atscott commented Sep 24, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.