Skip to content

Instantly share code, notes, and snippets.

@jkup
Created January 27, 2021 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkup/d19ee6e0e77f1c0b9c1d5d1de4a4e9d1 to your computer and use it in GitHub Desktop.
Save jkup/d19ee6e0e77f1c0b9c1d5d1de4a4e9d1 to your computer and use it in GitHub Desktop.
interface Admin {
id: string;
role: string;
}
interface User {
email: string;
}
function redirect(usr: Admin | User) {
if("role" in usr) {
// I was amazed TS knew this was an Admin type
adminOnly(usr.role);
} else {
normalUser(usr.email);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment