sveltejs / sveltejs/kit

`page.params.slug` throws type errors in the latest version

Open
#14,057 7 comments 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

types / typescript
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

Hi, I just updated to the latest version 2.26.1 and it started throwing errors on page.params.slug, which was not the case in the previous version 2.25.2.

As soon as I went back to the previous version, there are no errors. I see the merged PR from Rich for page.params, it's probably related to how things work now, but this can be problematic because the results are not the same as before.

Is this a breaking change?

No errors:

  • "@sveltejs/kit": "^2.25.2"
  • "svelte": "^5.36.15",
<!-- PageContent.svelte -->

<script lang="ts">
  import { page } from '$app/state'

  // ...

  // page.params: Page<Record<string, string>, string | null>.params: Record<string, string>
  let menuPage = $derived(getMenuPage(page.params.slug, page.url.pathname))

  // ...
</script>

Errors:

  • "@sveltejs/kit": "^2.26.1"
  • "svelte": "^5.36.17",
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.ts(2345)
<!-- PageContent.svelte -->

<script lang="ts">
  import { page } from '$app/state'

  // ...

  // page.params: Page<LayoutParams<"/">, RouteId | null>.params: LayoutParams<"/">
  let menuPage = $derived(getMenuPage(page.params.slug, page.url.pathname))

  // ...
</script>

page.params.slug is now slug?: string | undefined.

Reproduction

i write a simple example above...

Logs

System Info
macos
Severity

blocking an upgrade

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PageContent.svelte reproduction and compare the inferred type of page.params.slug between @sveltejs/kit 2.25.2 and 2.26.1, using the versions and error shown in the report. Trace the merged page.params change mentioned in the issue. Done means the regression is reproduced and either the typing matches the prior behavior or the intended breaking change is clearly established.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.