You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeCast<A,B>=AextendsB ? A : BtypeNarrowable=string|number|bigint|booleantypeNarrow<A>=Cast<A,[]|(AextendsNarrowable ? A : never)|{[KinkeyofA]: Narrow<A[K]>}>interfaceRouteRecordRaw{path: stringname: string}interfaceRouterOptions<RoutesextendsReadonlyArray<RouteRecordRaw>>{routes: Narrow<Routes>}functioncreateRouter<RoutesextendsReadonlyArray<RouteRecordRaw>>(options: RouterOptions<Routes>){returnoptions}constrouter=createRouter({routes: [{path: '/',name: 'home'}]})
The types are recursive but it's possible to change them in a way that infers only the routes array in case there is a nested array that should not be inferred.
The text was updated successfully, but these errors were encountered:
Thanks, this is interesting! I think that given the status of that API being experimental and how easy as const makes it to stop or start using it, I rather keep it until it gets out of its experimental state. After all, I don't want to force everybody use this experimental API because it has performance implications with large amounts of routes, due to the nature of the types and it would make the fastest computer lag 😆
I didn't know you could narrow a const type like this, It does work with arrays. It's a good trick to remember.
What problem does this feature solve?
This allows users to omit the
as const
when passing the routes array tocreateRouter
options, which results in better DX imo.What does the proposed API look like?
This might be possible thanks to this issue comment in typescript
microsoft/TypeScript#30680 (comment)
Here is how I think this could be implemented
The types are recursive but it's possible to change them in a way that infers only the routes array in case there is a nested array that should not be inferred.
The text was updated successfully, but these errors were encountered: