Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save charlypoly/4165b68e63fe4ef6c88c880310ba6b2e to your computer and use it in GitHub Desktop.
Save charlypoly/4165b68e63fe4ef6c88c880310ba6b2e to your computer and use it in GitHub Desktop.
TypeScript TSConfig intro example
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