Created
November 29, 2021 11:21
-
-
Save charlypoly/4165b68e63fe4ef6c88c880310ba6b2e to your computer and use it in GitHub Desktop.
TypeScript TSConfig intro example
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 isPremiumUser(user: User | PremiumUser): user is PremiumUser { | |
return user.plan === "premium" | |
} | |
let user: PremiumUser | User | undefined | |
// the line below should raise a TypeScript error, | |
// but it doesn't! | |
if (isPremiumUser(user)) { | |
// ... | |
} else { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment