Skip to content

Instantly share code, notes, and snippets.

@pffigueiredo
Last active March 6, 2023 16:55
Show Gist options
  • Save pffigueiredo/34ad1ec80385feae7783d91c628c3b6a to your computer and use it in GitHub Desktop.
Save pffigueiredo/34ad1ec80385feae7783d91c628c3b6a to your computer and use it in GitHub Desktop.
Type to figure out if it's an union
// When conditional types act on a generic type, they become distributive when given a union type
// So `("a" | "b") extends any` it's actually `"a" extends any | "b" extends any`
type IsUnion<T, C = T> = T extends C ? ([C] extends [T] ? false : true) : never;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment