Last active
February 15, 2024 07:25
-
-
Save ReVoid/6da2cc62dffc9f177e89f90b832c0c21 to your computer and use it in GitHub Desktop.
Swap unions utility
This file contains hidden or 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
type Swap<T, USubject, UTarget> = T extends USubject ? Exclude<T, USubject> | UTarget : T; | |
type Whatever = string | null; | |
// Swap null to undefined | |
type Swapped = Swap<Whatever, null, undefined>; // string | undefined | |
// TODO: Make a nested object implementation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment