Created
January 27, 2021 05:37
-
-
Save jkup/d19ee6e0e77f1c0b9c1d5d1de4a4e9d1 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
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