Skip to content

chore: fix navigation type duplicated descriptions#15490

Merged
teemingc merged 1 commit intomainfrom
chore-navigate-jsdocs
Mar 5, 2026
Merged

chore: fix navigation type duplicated descriptions#15490
teemingc merged 1 commit intomainfrom
chore-navigate-jsdocs

Conversation

@teemingc
Copy link
Member

@teemingc teemingc commented Mar 5, 2026

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 OnNavigate and AfterNavigate sections 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:

type A = {
  /** foo */
  example: 'foo';
}

type B = {
  /** bar */
  example: 'bar';
}

type C = A | B;

The description for C['example'] would be "foo bar".

However, if you have some overlap, TypeScript merges your descriptions as best as it can:

type A = {
  /**
  * This contains:
  * - foo
  */
  example: 'foo';
}

type B = {
  /**
  * This contains:
  * - bar
  */
  example: 'bar';
}

type C = A | B;

You'll end up with:

This contains:
- foo
- bar

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:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

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

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: f60345e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@svelte-docs-bot
Copy link

}

export interface NavigationExternal extends NavigationBase {
export type NavigationExternal = NavigationGoto | NavigationLeave;
Copy link
Member Author

@teemingc teemingc Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
Copy link
Member Author

@teemingc teemingc Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@teemingc teemingc merged commit 37ec6c8 into main Mar 5, 2026
28 checks passed
@teemingc teemingc deleted the chore-navigate-jsdocs branch March 5, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

afterNavigate's type property type has twice the documentation

2 participants