chore: fix navigation type duplicated descriptions#15490
Conversation
|
| } | ||
|
|
||
| export interface NavigationExternal extends NavigationBase { | ||
| export type NavigationExternal = NavigationGoto | NavigationLeave; |
There was a problem hiding this comment.
This had to be split into two types. Otherwise, their descriptions wouldn't be separable for AfterNavigate and OnNavigate which both exclude the 'leave' navigation type.
| to: NavigationTarget | null; | ||
| /** | ||
| * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation) | ||
| * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation). |
There was a problem hiding this comment.
The period helps separate this sentence from the next one it'll be concatenated with https://github.com/sveltejs/kit/pull/15490/changes#diff-9e558fcdee2759e3a180281c10a134e7caa6123e746f91178e20ec1b9d61be76R1364
closes #15470
This PR ensures that the type descriptions for the various navigation types show up correctly in the IDE when hovering over the type. This results in slightly worse docs when viewing the
OnNavigateandAfterNavigatesections but the trade-off is worth it. We get the correct descriptions after type-narrowing too.The thing about TypeScript and unions is that it tries to merge the description for similar properties. If you have something like:
The description for
C['example']would be "foo bar".However, if you have some overlap, TypeScript merges your descriptions as best as it can:
You'll end up with:
which works nicely for us in our case.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Not sure if this needs a changeset since the user isn't really affected... Maybe it does? Might even be a breaking change? The types should still be equivalent though.
Edits