Skip to content

Instantly share code, notes, and snippets.

@mscolnick
Created March 15, 2021 04:02
Show Gist options
  • Save mscolnick/73fa6fc26dd11b19c31b96a44a977070 to your computer and use it in GitHub Desktop.
Save mscolnick/73fa6fc26dd11b19c31b96a44a977070 to your computer and use it in GitHub Desktop.
type Unpacked<T> =
T extends (infer U)[] ? U :
T extends (...args: any[]) => infer U ? U :
T extends Promise<infer U> ? U :
T;
type T0 = Unpacked<string>; // string
type T1 = Unpacked<string[]>; // string
type T2 = Unpacked<() => string>; // string
type T3 = Unpacked<Promise<string>>; // string
type T4 = Unpacked<Promise<string>[]>; // Promise<string>
type T5 = Unpacked<Unpacked<Promise<string>[]>>; // string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment