Having
<Route path="/product/{id:Int}" page={ProductPage} name="product" />
would make routes.product({ id }) method available, but only string values are available.
This raises false error on .ts files.
routes.product({ id: 123 }) // Type 'number' is not assignable to type 'string'. ts(2322)

Here is the generated .redwood/types/routes.d.ts file:
import '@redwoodjs/router'
type ParseRouteParameters<Route> =
Route extends `${string}/{${infer Param}:${string}}/${infer Rest}`
? { [Entry in Param | keyof ParseRouteParameters<`/${Rest}`>]: string }
: Route extends `${string}/{${infer Param}:${string}}`
? { [Entry in Param]: string } // <-- HERE?
: Route extends `${string}/{${infer Param}}`
? { [Entry in Param]: string }
: Record<string, string>
declare module '@redwoodjs/router' {
interface AvailableRoutes {
product: (params?: ParseRouteParameters<"/product/{id:Int}">) => "/product/{id:Int}"
}
}
It should at least support core route parameter types.
I tried adding these two lines, and it seems to fix the issue.
type ParseRouteParameters<Route> =
Route extends `${string}/{${infer Param}:${string}}/${infer Rest}`
? { [Entry in Param | keyof ParseRouteParameters<`/${Rest}`>]: string }
// check for Int type
: Route extends `${string}/{${infer Param}:Int}`
? { [Entry in Param]: number }
: Route extends `${string}/{${infer Param}:${string}}`
? { [Entry in Param]: string }
: Route extends `${string}/{${infer Param}}`
? { [Entry in Param]: string }
: Record<string, string>
Having
would make
routes.product({ id })method available, but onlystringvalues are available.This raises false error on
.tsfiles.Here is the generated
.redwood/types/routes.d.tsfile:It should at least support core route parameter types.
I tried adding these two lines, and it seems to fix the issue.