Skip to content

Instantly share code, notes, and snippets.

@barfi
Last active October 13, 2023 13:59
Show Gist options
  • Save barfi/44bfc0b4631247f81b0d32b3bd879f0c to your computer and use it in GitHub Desktop.
Save barfi/44bfc0b4631247f81b0d32b3bd879f0c to your computer and use it in GitHub Desktop.

Revisions

  1. barfi revised this gist Oct 13, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ type RemovePrefixFromStruct<T> = {
    }

    const user = {
    name: 'Ivan',
    name: 'John',
    age: 25,
    lastName: 'Petrov'
    } satisfies RemovePrefixFromStruct<UserData>
    lastName: 'Doe'
    } satisfies RemovePrefixFromStruct<UserStruct>
  2. barfi revised this gist Oct 13, 2023. 1 changed file with 17 additions and 2 deletions.
    19 changes: 17 additions & 2 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,17 @@
    //
    s
    type UserStruct = {
    'prefix:name': string
    'prefix:age': number
    lastName: string
    }

    type RemovePrefix<T> = T extends `prefix:${infer U}` ? U : T

    type RemovePrefixFromStruct<T> = {
    [K in keyof T as RemovePrefix<K>]: T[K]
    }

    const user = {
    name: 'Ivan',
    age: 25,
    lastName: 'Petrov'
    } satisfies RemovePrefixFromStruct<UserData>
  3. barfi created this gist Oct 13, 2023.
    2 changes: 2 additions & 0 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    //
    s