Created
April 27, 2022 02:28
-
-
Save ankitr/42700384e970fbb0d36d66a0bd875727 to your computer and use it in GitHub Desktop.
Camel case from snake case TypeScript string literals
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
const a = 'snake_case'; | |
type CamelCaseFromSnakeCase<Snake extends string> = | |
Snake extends `${infer First}_${infer Rest}` | |
? `${First}${Capitalize<CamelCaseFromSnakeCase<Rest>>}` | |
: Snake; | |
const b: CamelCaseFromSnakeCase<typeof a> = 'snakeCase'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment