Skip to content

Instantly share code, notes, and snippets.

@alxpsr
Created November 14, 2022 18:14
Show Gist options
  • Select an option

  • Save alxpsr/189a49ec362215574ffc322e595c30e8 to your computer and use it in GitHub Desktop.

Select an option

Save alxpsr/189a49ec362215574ffc322e595c30e8 to your computer and use it in GitHub Desktop.

Revisions

  1. alxpsr created this gist Nov 14, 2022.
    13 changes: 13 additions & 0 deletions Infer.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    const User = {
    id: 123,
    username: 'John',
    email: '[email protected]',
    addons: [
    { name: 'First addon', id: 1 },
    { name: 'Second addon', id: 2 }
    ]
    }

    type UnpackArray<T> = T extends (infer R)[] ? R : T

    type AddonType = UnpackArray<typeof User.addons> // { name: string, id: number }