Skip to content

Instantly share code, notes, and snippets.

@semlinker
Created October 15, 2022 15:19
Show Gist options
  • Save semlinker/7cc1f7f5cd819dae3ddc470511f4b7c7 to your computer and use it in GitHub Desktop.
Save semlinker/7cc1f7f5cd819dae3ddc470511f4b7c7 to your computer and use it in GitHub Desktop.
TypeName Utility Type
type TypeName<T> =
T extends string ? "string" :
T extends number ? "number" :
T extends boolean ? "boolean" :
T extends undefined ? "undefined" :
T extends Function ? "function" :
"object";
// "string" | "function"
type T10 = TypeName<string | (() => void)>;
// "string" | "object" | "undefined"
type T11 = TypeName<string | string[] | undefined>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment