Last active
March 6, 2023 16:55
-
-
Save pffigueiredo/34ad1ec80385feae7783d91c628c3b6a to your computer and use it in GitHub Desktop.
Type to figure out if it's an union
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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