We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
working example to contraint developer to pass existing route name to createUrl
createUrl
import { Route } from "@wbe/low-router" // routes const ROUTES = [ { name: "home", children: [ { name: "dashboard" }, { name: "profile", children: [{ name: "hello" }, { name: "foo" }], }, ], }, { name: "about" }, { name: "contact" }, ] as const satisfies Route[] // this is the trick to allow route names casting // fake router type RouteNames<R> = R extends { name: infer N; children: infer C } ? N | RouteNamesFromArray<C> : R extends { name: infer N } ? N : never type RouteNamesFromArray<A> = A extends readonly (infer R)[] ? RouteNames<R> : never class Router<T extends Route[]> { routes: T constructor(routes: T) { this.routes = routes } public createUrl({ name }: { name: RouteNamesFromArray<T> }) { console.log(`Creating URL for route name: ${name}`) } } const router = new Router(ROUTES) router.createUrl({ name: "about" })
The text was updated successfully, but these errors were encountered:
No branches or pull requests
working example to contraint developer to pass existing route name to
createUrl
The text was updated successfully, but these errors were encountered: