Created
September 7, 2021 20:35
-
-
Save olafsulich/b0dc694ee474ee8c9b303a873b5bc026 to your computer and use it in GitHub Desktop.
TypeScript - parse route parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ParseRouteParameters<Route> = Route extends `${string}/:${infer Param}/${infer Rest}` | |
? { [Entry in Param | keyof ParseRouteParameters<`/${Rest}`>]: string } | |
: Route extends `${string}/:${infer Param}` | |
? { [Entry in Param]: string } | |
: {}; | |
type X = ParseRouteParameters<'/api/:what/:is/notyou/:happening'>; | |
// type X = { | |
// what: string, | |
// is: string, | |
// happening: string, | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment