-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Labels
Description
Describe the bug
I have this locale param matcher:
import type { ParamMatcher } from "@sveltejs/kit";
const locales = ["en", "nb"] as const;
export const match = ((value): value is (typeof locales)[number] => {
return locales.includes(value);
}) satisfies ParamMatcher;When looking at .svelte-kit/types/src/routes/[[locale=locale]]/$types.d.ts, I see this:
type MatcherParam<M> = M extends (param : string) => param is infer U ? U extends string ? U : string : string;
type RouteParams = { locale?: MatcherParam<typeof import('../../../../../src/params/locale.js').match> };But in .svelte-kit/non-ambient.ts, it looks like this:
declare module "$app/types" {
export interface AppTypes {
RouteParams(): {
"/[[locale=locale]]": { locale?: string }
};
};
}As a result, in src/routes/[[locale=locale]]/+page.svelte, the params prop is typed correctly, but not the page.params from $app/state.
<script lang="ts">
import type { PageProps } from "./$types.js";
import { page } from "$app/state";
let { params }: PageProps = $props();
params.locale; // "en" | "no" | undefined
page.params.locale; // string | undefined
</script>For the same reason, the params are also incorrectly typed in hooks.
I think non-ambient.ts should use the same approach as $types.d.ts to provide correct types for route params.
Reproduction
Logs
System Info
N/ASeverity
annoyance
Additional Information
No response
Reactions are currently unavailable