Skip to content

Instantly share code, notes, and snippets.

@davlet61
Last active February 22, 2023 13:36
Show Gist options
  • Select an option

  • Save davlet61/61ff6bc39fdcb1c4d02c990b7198d55b to your computer and use it in GitHub Desktop.

Select an option

Save davlet61/61ff6bc39fdcb1c4d02c990b7198d55b to your computer and use it in GitHub Desktop.

Revisions

  1. davlet61 revised this gist Feb 22, 2023. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion snakeTocamel.ts
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,9 @@ type SnakeToCamelCase<T> = T extends `id${infer S}_${infer N}`
    ? `${F}${Capitalize<N>}`
    : T;

    type MappedType<T> = { [K in keyof T as SnakeToCamelCase<K>] : T[K] };
    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.
    */
  2. davlet61 renamed this gist Feb 22, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. davlet61 renamed this gist Jan 31, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. davlet61 created this gist Jan 31, 2023.
    7 changes: 7 additions & 0 deletions file.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    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] };