Skip to content

Instantly share code, notes, and snippets.

@srigi
Created May 10, 2023 12:36
Show Gist options
  • Save srigi/795f286bb67a031d918c5b969ca6e54c to your computer and use it in GitHub Desktop.
Save srigi/795f286bb67a031d918c5b969ca6e54c to your computer and use it in GitHub Desktop.
Typescript discriminated union with non-mutual prop
type T =
| { x: true, y: string | null }
| { x?: never, y: string }
or
if ("x" in t) {
console.log(t.x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment