Skip to content

Instantly share code, notes, and snippets.

@mscolnick
Created March 15, 2021 04:01
Show Gist options
  • Save mscolnick/a44b77b137bec16c309ffea92b5c8f23 to your computer and use it in GitHub Desktop.
Save mscolnick/a44b77b137bec16c309ffea92b5c8f23 to your computer and use it in GitHub Desktop.
type TypeName<T> =
T extends string ? "string" :
T extends number ? "number" :
T extends boolean ? "boolean" :
T extends undefined ? "undefined" :
T extends Function ? "function" :
"object";
type T0 = TypeName<string>; // "string"
type T1 = TypeName<"a">; // "string"
type T2 = TypeName<true>; // "boolean"
type T3 = TypeName<() => void>; // "function"
type T4 = TypeName<string[]>; // "object"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment