Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Snake case to CammelCase
interface Example {
first_name: string,
last_name: string,
home_town: string,
type CamelizeString<T extends PropertyKey> = T extends string ? string extends T ? string :
T extends `${infer F}_${infer R}` ? `${F}${Capitalize<CamelizeString<R>>}` : T : T;
type Camelize<T> = { [K in keyof T as CamelizeString<K>]: T[K] }
type CamelizeExample = Camelize<Example>;
/* type CamelizeExample = {
firstName: string;
lastName: string;
homeTown: string;
} */
const e: Camelize<Example> = {
firstName: 'string',
lastName: 'string',
homeTown: 'string'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment