Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save charlypoly/4e01228440e9344ba3abd0392068e6d1 to your computer and use it in GitHub Desktop.
Save charlypoly/4e01228440e9344ba3abd0392068e6d1 to your computer and use it in GitHub Desktop.
TypeScript Discriminated Unions on destructured properties
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