Last active
February 22, 2023 13:36
-
-
Save davlet61/61ff6bc39fdcb1c4d02c990b7198d55b to your computer and use it in GitHub Desktop.
Snake to Camel
This file contains hidden or 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 SnakeToCamelCase<T> = T extends `id${infer S}_${infer N}` | |
| ? `${SnakeToCamelCase<N>}Id${S}` | |
| : T extends `${infer F}_${infer N}` | |
| ? `${F}${Capitalize<N>}` | |
| : T; | |
| type MappedType<T> = { [K in keyof T as SnakeToCamelCase<K>] : T[K] }; | |
| /* | |
| This is a specific case where some of the snake case types start with `ids`. | |
| The snippet can be easily modified for any use case. | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment