Created
September 1, 2020 06:13
-
-
Save Lucifier129/ef6e1f12b92938e8c19ff6fbc97276b2 to your computer and use it in GitHub Desktop.
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 ToTS<T extends string> = | |
T extends 'Int' | |
? number | |
: T extends 'String' | |
? string | |
: T extends 'Bool' | |
? boolean | |
: never | |
type ParamType<T extends string> = | |
T extends `<${infer ParamName}:${infer ParamType}>` | |
? { [key in ParamName]: ToTS<ParamType> } | |
: {} | |
type ParamsType<T extends string> = | |
T extends `/${infer Param}/${infer Rest}` | |
? ParamType<Param> & ParamsType<`/${Rest}`> | |
: T extends `/${infer Param}` | |
? ParamType<Param> | |
: {} | |
type PathToRegExp<T extends string> = { | |
[key in keyof ParamsType<T>]: ParamsType<T>[key] | |
} | |
type T1 = PathToRegExp<`/users/<id:Int>/<name:String>/<isVip:Bool>`> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment