Skip to content

Type route id and params together #15619

@Stadly

Description

@Stadly

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions