Created
January 30, 2023 21:09
-
-
Save Grubba27/0ddac06be68b7c637d0c7eb266f0565a to your computer and use it in GitHub Desktop.
Get url params
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 GetParams< | |
Text extends string, | |
Result extends string = '' | |
> = | |
Text extends `${ infer L }${ infer R }` | |
? L extends '/' | |
? Result | |
: GetParams<R, `${ Result }${ L }`> | |
: Result | |
type GetURLParams<URL extends string, Params = {}, > = | |
URL extends `${ infer L }${ infer R }` | |
? L extends ':' | |
? GetURLParams<R, { [p in GetParams<R>]: string } & Params> | |
: GetURLParams<R, Params> | |
: Params | |
let url: GetURLParams<'/:id/:d2/'> = {d2: '', id: ''} | |
let url: GetURLParams<'/:other/:d2/'> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment