Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Last active August 17, 2022 15:07
Show Gist options
  • Save jmaicaaan/5ad54554225ca6406c04baba1adb06bf to your computer and use it in GitHub Desktop.
Save jmaicaaan/5ad54554225ca6406c04baba1adb06bf to your computer and use it in GitHub Desktop.
export type CamelizeString<ObjectProperty extends string> =
ObjectProperty extends `${infer F}_${infer R}`
? `${F}${Capitalize<CamelizeString<R>>}`
: ObjectProperty;
export type Camelize<GenericObject> = {
[ObjectProperty in keyof GenericObject as CamelizeString<ObjectProperty & string>]:
GenericObject[ObjectProperty] extends Array<infer ArrayItem>
? ArrayItem extends Record<string, unknown>
? Array<Camelize<ArrayItem>>
: GenericObject[ObjectProperty]
: GenericObject[ObjectProperty] extends Record<string, unknown>
? Camelize<GenericObject[ObjectProperty]>
: GenericObject[ObjectProperty];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment