Created
November 29, 2021 11:15
-
-
Save charlypoly/4e01228440e9344ba3abd0392068e6d1 to your computer and use it in GitHub Desktop.
TypeScript Discriminated Unions on destructured properties
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
type UserArg = PremiumUser | USer | |
function processUSer({ plan, premiumOptions }: UserArg) { | |
if (plan === "premium") { | |
premiumOptions | |
// `premiumOptions` is of type `PremiumOptions` | |
} else { | |
premiumOptions | |
// `premiumOptions` is of type `undefined` | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment