-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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(router): remove RouterEvent from Event union type #46061
Conversation
@cexbrayat This was actually done intentionally due to concerns around introducing a breaking change and time pressure with the v14 feature freeze. I've triggered internal presubmits to see how breaking this change really would be. |
As expected, this is a breaking change. In particular, it would break this particular pattern to filter to the parent type (for example, if you want any event with an
While we could consider not supporting this use-case in the same way, it's certainly not something we can just squeeze in to the v14 release since the RC is out and we can't introduce new breaking changes. I'm going to close this since it's not feasible to land now. Could you open a feature request so we can gauge community interest and determine how much we should prioritize it for v15? |
@atscott I don't think it's particularly useful, it's just that the addition of |
@cexbrayat The intent was a resolution for #43762. Removing it from the changelog doesn't make sense because the change is merged and committed and we won't be reverting it. It's not as useful as it could be, but it's not entirely useless. |
You should be able to use this form instead with the filter: The need to hint that the filter function is type narrowing is unfortunately verbose in either case. It may be useful to introduce a series of helper functions (e.g., |
@cexbrayat To be clear, I do think this is worth a feature request. You're absolutely right that the experience is not ideal at the moment. |
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. |
@cexbrayat Would you be interesting in reopening and rebasing this change? We should hopefully be able to land this in v15. |
87f9fe0
to
bdd4280
Compare
@clydin Sure, done! |
@cexbrayat The team was really busy with a bunch of talks and conferences leading up to v15 so we didn't have time to do the internal cleanup necessary to land this before the feature freeze several weeks back. That said, we'll definitely get this in to v16. I'm doing the cleanup now and will add a patch to include this change so we don't have any regressions and will be able to merge as soon as the That said, can you add the |
@atscott Hi Andrew. No problem, I amended the commit, quoting your example as a use-case. Let me know if that's OK. |
a55af09
to
3453d6e
Compare
quick update: This change has been patched into Google's codebase. That means there will be no internal cleanup needed when we're ready to merge this to the v16 branch. |
1925918
to
77093a4
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.
LGTM with one tiny non-code request: Can we update the commit message to describe the final result rather than the existing problem? i.e. "fix(router): Remove RouterEvent
from Event
type union to ..." or something to that effect
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
41e2a68 added a `type` property on all router events, and added all type of events to the `Event` union type, but forgot to remove `RouterEvent`. This removes the benefit of the `type` field, because it is not possible to write: ``` this.router.events.pipe(filter((event: Event): event is NavigationEnd => event.type === EventType.NavigationEnd)).subscribe(/*...*/); ``` as `RouterEvent` does not have a `type` field (hence TS complains). This commit fixes the issue by removing `RouterEvent` from the union type. BREAKING CHANGE: The `RouterEvent` type is no longer present in the `Event` union type representing all router event types. If you have code using something like `filter((e: Event): e is RouterEvent => e instanceof RouterEvent)`, you'll need to update it to `filter((e: Event|RouterEvent): e is RouterEvent => e instanceof RouterEvent)`.
77093a4
to
2f86dc6
Compare
@atscott Sure, done 👍 |
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
merge assistance: This change is already patched in to g3. When syncing this commit, you'll need to also remove the |
This PR was merged into the repository by commit 1e32709. |
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. |
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?
41e2a68 added a
type
property on all router events, and added all type of events to theEvent
union type, but forgot to removeRouterEvent
.This removes the benefit of the
type
field, because it is not possible to write:as
RouterEvent
does not have atype
field (hence TS complains).What is the new behavior?
This commit fixes the issue by removing
RouterEvent
from the union type.Does this PR introduce a breaking change?
Other information