-
-
Save blemoine/07c72a73e73149d7af16de5d35cd03d8 to your computer and use it in GitHub Desktop.
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
function isUser(a: any): a is {name: string} { | |
return typeof a === 'number'; | |
} | |
const num: number = 3; | |
if (isUser(num)) { | |
console.log(num.name); //compiles fine, TS thinks that num is a {name: string} here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment