Skip to content

Instantly share code, notes, and snippets.

@maxgfr
Last active May 17, 2025 08:54
Show Gist options
  • Save maxgfr/a089fbd909b276528fc18adc3d19506a to your computer and use it in GitHub Desktop.
Save maxgfr/a089fbd909b276528fc18adc3d19506a to your computer and use it in GitHub Desktop.
Useful types in typescript
export type CamelCase<S extends string> =
S extends `${infer P1}_${infer P2}${infer P3}`
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
: Lowercase<S>;
export type KeysToCamelCase<T> = {
[K in keyof T as CamelCase<string & K>]: T[K] extends {}
? KeysToCamelCase<T[K]>
: T[K];
};
export type ValueOf<T> = T[keyof T];
export type Prettify<T> = {[K in keyof T] : T[K]}
export type LooseAutocomplete<T extends string> = T | Omit<string , T>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment