I'm creating a component that will receive several RouteId and create links
I want to use the resolve fn to validate them
see: https://svelte.dev/docs/kit/$app-paths#resolve
If I declare a prop (or a variable) like RouteId, typescript effectively validates that it is a valid route
the problem is that resolve fn does not recognize it
import { resolve } from '$app/paths';
import type { RouteId } from '$app/types';
// this is OK, typescript validates that path IS a valid route
console.log('myResolve: ', myResolve('/api/health'));
function myResolve(path: RouteId) {
return resolve(path); // but resolve DOES NOT ACCEPT type RouteId
}
the error:
Error: Argument of type '["/api/endpoint1" | "/api/endpoint2" ... 20 more ... | [route: ...]'.
Type '"/xxxx"' is not assignable to type '"/yy"'. (ts)
function myResolve(path: RouteId) {
return resolve(path); // but resolve DOES NOT ACCEPT type RouteId
}
I had to solve it like this:
<!-- eslint-disable @typescript-eslint/no-explicit-any -->
<!-- Reason: resolve cannot recognize demo.href as a valid RouteId type, we bypass the verification. -->
<a
class="font-medium text-foreground transition-colors hover:text-primary"
href={resolve(demo.href as any)}
>
{demo.name}
</a>
how can I tell resolve function that demo.href is a valid RouteId, which it effectively is
update: I tried with what @brunnerh suggestion, same error
Argument of type '[route: "/"] | [route: "/api"] | [route: "/api/health"] | ... 58 more ... | [route: ...]'.
[...]
Type at position 0 in source is not compatible with type at position 0 in target.
Type '"/api/provincias/[provincia]" | "/api/provincias/[provincia]/departamentos" | "/api/provincias/[provincia]/departamentos/[departamento]" | "/api/provincias/[provincia]/departamentos/[departamento]/localidades"' is not assignable to type '"/api/provincias/[provincia]"'.
Type '"/api/provincias/[provincia]/departamentos"' is not assignable to type '"/api/provincias/[provincia]"'.ts(2345)

