`RouteId` is not a valid param for `resolve()`
Describe the bug
Hi, starting somewhere on 2.50+ (cannot remember exact version, sorry), I started getting strange errors, where a manually type RouteId cannot be passed as a first argument to resolve(), even though it should explicitly work with that as per the docs.
Reproduction
The linked Stackblitz doesn't boot, so a more full repro:
<script lang="ts">
import type { RouteId } from "$app/types";
import { goto } from "$app/navigation";
import { resolve } from "$app/paths";
void goto(
resolve("whatever" as RouteId),
);
</script>
Logs
I get this when running svelte-check:
Error: Argument of type '["/" | "/blog" | "/blog/hyperparameter-optimization-for-gnns-with-transfer-learning" | "/publications" | "/teaching" | "/teaching/LAL1" | "/teaching/LAL1/2021-winter" | ... 19 more ... | "/vyuka"]' is not assignable to parameter of type '[route: "/"] | [route: "/blog"] | [route: "/blog/hyperparameter-optimization-for-gnns-with-transfer-learning"] | [route: "/publications"] | [route: "/teaching"] | [route: "/teaching/LAL1"] | [route: "/teaching/LAL1/2021-winter"] | ... 19 more ... | [route: ...]'.
Type '["/" | "/blog" | "/blog/hyperparameter-optimization-for-gnns-with-transfer-learning" | "/publications" | "/teaching" | "/teaching/LAL1" | "/teaching/LAL1/2021-winter" | ... 19 more ... | "/vyuka"]' is not assignable to type '[route: "/vyuka"]'.
Type '"/" | "/blog" | "/blog/hyperparameter-optimization-for-gnns-with-transfer-learning" | "/publications" | "/teaching" | "/teaching/LAL1" | "/teaching/LAL1/2021-winter" | ... 19 more ... | "/vyuka"' is not assignable to type '"/vyuka"'.
Type '"/"' is not assignable to type '"/vyuka"'. (ts)
void goto(
resolve(`/teaching/${course?.slug ?? ""}/${newVersion}` as RouteId),
);
System Info
❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
System:
OS: Linux 6.17 Ubuntu 25.10 25.10 (Questing Quokka)
CPU: (24) x64 AMD Ryzen AI 9 HX 370 w/ Radeon 890M
Memory: 14.28 GB / 30.13 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 24.11.0 - /usr/bin/node
Yarn: 1.22.22 - /usr/bin/yarn
npm: 11.8.0 - /usr/bin/npm
pnpm: 10.30.0 - /usr/bin/pnpm
Browsers:
Firefox: 148.0
Firefox Developer Edition: 148.0
npmPackages:
@sveltejs/adapter-static: ^3.0.10 => 3.0.10
@sveltejs/enhanced-img: ^0.10.3 => 0.10.3
@sveltejs/kit: ^2.54.0 => 2.54.0
@sveltejs/vite-plugin-svelte: ^6.2.4 => 6.2.4
svelte: ^5.53.6 => 5.53.6
vite: ^7.3.1 => 7.3.1
Severity
serious, but I can work around it
Additional Information
I was waiting for 2.54 and tried RouteIdWithSearchOrParams, but that doesn't fix it either.
We hit the same issue in our project (SvelteKit 2.54.0, ~35 files affected). When passing a variable typed as Pathname or RouteId (the full generated union) to resolve(), TypeScript fails to distribute ResolveArgs<T> correctly over the large union — resulting in Expected 2 arguments, but got 1 (TS2554).
String literals work fine (resolve('/about') ✓), but variables don't (resolve(somePathname) ✗).
Workaround: Module augmentation in src/app.d.ts — adds a plain string fallback overload:
declare module '$app/paths' {
export function resolve(pathname: string): string;
}
- String literals still match the generic overload first → full type safety preserved
- Variable strings fall back to the simple overload → compiles correctly
- Zero runtime code, no wrapper functions needed
Thanks, that's definitely a workaround, but it does not, in fact, preserve full type safety as you can then pass any (even invalid) route to resolve()
Yeah fair point, variables can still bypass route validation. But honestly same tradeoff as the old (resolve as (p: string) => string)(path) pattern, just less ugly. Hoping for a proper fix from the Kit team 🙏
Hi,
I investigated this a little bit more and I think I know what the trigger is: I have (among many others) a /blog/something route, but I don't have a /blog route in my app. This makes it so that my .svelte-kit/non-ambient.d.ts looks something like this:
declare module "$app/types" {
export interface AppTypes {
RouteId(): "/" | "/blog" | "/blog/something" | "/other";
Pathname(): "/" | "/blog/something" | "/other";
}
}
Notice the difference.
I also have a lot of other routes, but the problem appeared with the addition of the /blog/something route. That means it may not be tied to a SvelteKit version upgrade as I originally thought.
Hi, I let Claude investigate a little bit more in my repo, here's its summary (not explicitly verified by me, but sounds reasonable):
Root Cause Analysis
The bug is real and your report is essentially correct, but the precise TypeScript mechanism causing it is worth spelling out.
The resolve() type signature
// In $app/paths (kit/types/index.d.ts)
export function resolve<T extends RouteId | Pathname>(...args: ResolveArgs<T>): ResolvedPathname;
type ResolveArgs<T extends RouteId | Pathname> = T extends RouteId
? RouteParams<T> extends Record<string, never>
? [route: T]
: [route: T, params: RouteParams<T>]
: [route: T];
What happens when you call resolve(x) where x: RouteId
TypeScript's conditional types are distributive — when the type parameter is a union, the condition distributes over each member:
ResolveArgs<"/" | "/blog" | ...>
= ResolveArgs<"/"> | ResolveArgs<"/blog"> | ...
= [route: "/"] | [route: "/blog"] | ... ← union of singleton tuples
But the actual argument at the call site is [x], which has type: ["/" | "/blog" | ...] ← singleton tuple containing a union
TypeScript then checks: is ["/" | "/blog" | ...] assignable to [route: "/"] | [route: "/blog"] | ...?
No. A tuple containing a union is NOT assignable to a union of tuples. This is a fundamental TypeScript limitation — distribution happens at type evaluation time, not at call-site assignability checking. You can verify with a minimal repro:
type AB = "a" | "b";
type Args<T extends AB> = T extends "a" ? [x: "a"] : [x: "b"];
declare function f<T extends AB>(...args: Args<T>): void;
declare const x: AB;
f(x); // Error: ["a" | "b"] not assignable to ["a"] | ["b"]
f("a"); // OK: T inferred as "a", Args<"a"> = ["a"]
This is exactly the error you're seeing.
Why specific literal strings work but RouteId doesn't
When you write resolve("/teaching/LAL1/2021-winter"), TypeScript infers T = "/teaching/LAL1/2021-winter" (a specific literal, not the union), so ResolveArgs<T> evaluates to [route: "/teaching/LAL1/2021-winter"] — a single concrete tuple, which the argument matches perfectly.
When you write resolve(route) where route: RouteId (the full union), TypeScript infers T = RouteId, distributes, gets a union of tuples as the expected type, and the actual argument tuple-of-union fails the assignability check.
Is this a regression (2.50+) or was it always broken?
Your issue says "starting around 2.50+". Looking at the installed version (2.53.4), the resolve() function was added at since 2.26 with the same ResolveArgsRouteId union type from day one — the fix was never there to begin with. It may have gone unnoticed because:
- Most early users called
resolve()with literal strings (the docs show this), not withRouteIdvariables - Users might only have started hitting this when migrating away from base + route patterns
The bug is in SvelteKit's type design
ResolveArgs<T> using a distributive conditional as a rest parameter is excellent for checking specific literal routes but fundamentally incompatible with the RouteId union type. The correct fix on SvelteKit's side would be to use explicit TypeScript overloads:
// For routes with no dynamic params
export function resolve(route: RouteId extends keyof RouteParamsMap ? never : RouteId): ResolvedPathname;
// Or more practically, just add an overload that accepts RouteId directly
Or restructure so the type parameter doesn't create the union-of-tuples problem.
What your report might be getting slightly wrong
The issue title says "RouteId is not a valid param for resolve()". This is correct. But the description might give the impression that RouteId was valid before 2.50 — based on my analysis, it has never worked for the full union type. The right framing for the issue report is: the resolve() function's type signature does not support the RouteId type despite RouteId being the documented way to represent "any valid route", and this has been the case since resolve() was introduced.
The key files involved:
- Type definition: node_modules/@sveltejs/kit/types/index.d.ts:127314 (the $app/paths module)
- ResolveArgs conditional type at node_modules/@sveltejs/kit/src/runtime/app/paths/types.d.ts:3
- The four affected files in your project all pass RouteId (the union) to resolve()
I'm leaving a comment here to say I too have this issue. I'm just creating a simple button component that takes some kind of URL and passes it through to the resolve unfortunately the typing that resolve is utilizing isn't exposed.
I get that it's generated for the routes which is great, but it would be nice if we could consume that more easily in scenarios like this, that way component parameters can handle the typing on the arguments like resolve does.
For now it seems I'll just have to accept a handler/callback that can be invoked which is a bit heavier but keeps things sane.
Just imagine though if you could expose the type you'd get quick feedback on whether or not a route was valid or invalid when you made changes. You can still have that utilizing the resolve function right now, but it would be nice to remove that level of coupling, or maybe it's just a necessary evil for now to handle more complex routing¿ 🤷 For now I still have to quiet the linter at the consumption site in the button, but now I can feed it the resolver.
goto(resolve('/hello')) used to work fine for months. Now, all of them error. No changes in what versions of packages I'm using. It insists that resolve needs a second parameter. It didn't used to.
@justingoldentrulioo I think that's a different issue (or maybe not an issue even, but intended behaviour)
Thanks for the reply @marekdedic.
It didn't used to do that. Are you saying it's intended behavior that in every single resolve() call I now need a second parameter for an empty object rather than just defaulting to empty object if the parameter isn't sent like how it worked before?
If that's the case, I can go through and update all my files. But if it's not intended then I'd rather get to the bottom of it and fix it for good.
(But yeah, that seems like it's actually a separate issue from this RouteId issue... my bad)
@justingoldentrulioo I'm not a maintainer, so 🤷 . I'd recommend opening a separate issue and discussing there.