Improved types | Handling for Boolean and Float route params#2177
Improved types | Handling for Boolean and Float route params#2177dac09 merged 8 commits intoredwoodjs:mainfrom
Conversation
|
Now, if you want to be more like RAILS (and who doesn't) then you may want If you want to get really crazy, what about |
I'd say its a good idea, but I've had enough of named route params |
|
HAHAHAHA |
| ).toEqual({ | ||
| match: true, | ||
| params: { | ||
| floatyMcFloat: 1.58, |
There was a problem hiding this comment.
These params are for you @cannikin to enjoy
| '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 } : Route extends `${string}/{${infer Param}}` ? { [Entry in Param]: string } : Record<string, string>' | ||
| 'type ParamType<constraint> = constraint extends "Int" ? number : constraint extends "Boolean" ? boolean : constraint extends "Float" ? number : string;' + | ||
| '\n' + | ||
| 'type RouteParams<Route> = Route extends `${string}/{${infer Param}:${infer Constraint}}/${infer Rest}` ? { [Entry in Param | keyof RouteParams<`/${Rest}`>]: ParamType<Constraint> } : Route extends `${string}/{${infer Param}:${infer Constraint}}` ? { [Entry in Param]: ParamType<Constraint> } : Route extends `${infer Constraint}/{${infer Param}}` ? { [Entry in Param]: ParamType<Constraint> } : Record<string, string | number>' |
Hmm in all seriousness should we implement 0/1? Would it actually be a legit case in a url parameter (and not a query param?). Query accepting 0/1 makes sense, but the path itself... dunno. Typescript for example would complain that you're trying to set a number instead of a bool |
|
OHHHH good point, these are path params, not query params. Nevermind! |
|
Just so we don't forget to document this: https://github.com/redwoodjs/redwoodjs.com/issues/658 |

Fixes #2169
What?
Lots of improvements to type generation, and handling params for routes
FloatandBooleantypes in routes e.g.Not 100% sure how useful the boolean one is, but hey.