Created
May 10, 2023 12:36
-
-
Save srigi/795f286bb67a031d918c5b969ca6e54c to your computer and use it in GitHub Desktop.
Typescript discriminated union with non-mutual prop
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 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