sveltejs / sveltejs/kit

Type route id and params together

Open
#15,619 3 comments 2 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 problem
import { resolve } from "$app/paths";
import { page } from "$app/state";

// TypeScript does not know that the params will always match the route id here:
resolve(page.route.id, page.params)
Describe the proposed solution

Would it be possible to let TypeScript know that the params match the route id if we put params inside route? So instead of having page.route.id be any RouteId and page.params be any Params, page.route would be something like

type Route =
  | { id: "/"; params: never }
  | { id: "/admin/[id]"; params: { id: string } }
  | { id: "/[locale=locale]/test"; params: { locale: "en" | "nb" } };

Then I think TypeScript would be able to know that params match id, and would not complain on resolve(page.route.id, page.route.params).

Alternatives considered

No response

Importance

nice to have

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 by tracing the TypeScript definitions behind $app/paths, $app/state, resolve, page.route.id, and page.params. Determine where route ids and parameter types are generated or connected, then verify that combining them under page.route allows resolve(page.route.id, page.route.params) without a type error while preserving the proposed route-specific parameter types.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.