Last active
February 25, 2021 16:35
-
-
Save mdarens/ff57aa49209974bb38e258e0d44dbd17 to your computer and use it in GitHub Desktop.
urlcat types where params can be inferred from path template
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
declare module "urlcat" { | |
type PathTemplateTokens< | |
Rte | |
> = Rte extends `${string}/:${infer P}/${infer Rest}` | |
? P | PathTemplateTokens<`/${Rest}`> | |
: Rte extends `${string}/:${infer P}` | |
? P | |
: never; | |
function urlcat< | |
BaseUrl extends string, | |
Params extends Record<string, string | number> | |
>(baseUrl: BaseUrl, params: Params): string; | |
function urlcat<BaseUrl extends string, PathTemplate extends string>( | |
baseUrl: BaseUrl, | |
pathTemplate: PathTemplate | |
): string; | |
function urlcat< | |
BaseUrl extends string, | |
PathTemplate extends string, | |
Params extends Record<PathTemplateTokens<PathTemplate>, string | number> | |
>(baseUrl: BaseUrl, pathTemplate: PathTemplate, params: Params): string; | |
export default urlcat; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See balazsbotond/urlcat#138