Skip to content

Instantly share code, notes, and snippets.

@ReVoid
Last active February 15, 2024 07:25
Show Gist options
  • Save ReVoid/6da2cc62dffc9f177e89f90b832c0c21 to your computer and use it in GitHub Desktop.
Save ReVoid/6da2cc62dffc9f177e89f90b832c0c21 to your computer and use it in GitHub Desktop.
Swap unions utility
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