Created
November 29, 2021 10:52
-
-
Save charlypoly/81ccf51dea0e063dbc4775a7bd1ba605 to your computer and use it in GitHub Desktop.
TypeScript equality narrowing
This file contains hidden or 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
function example(x: string | number, y: string | boolean) { | |
if (x === y) { | |
x | |
// `x` is of type `string` | |
y | |
// `y` is of type `string` | |
} else { | |
x | |
// `x` is of type `string | number` | |
y | |
// `y` is of type `string | boolean` | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment