Created
February 11, 2024 12:01
-
-
Save turbod/f9dab7d3c34f59460af408b0b994e271 to your computer and use it in GitHub Desktop.
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
type Email = string & { __brand: "Email" }; | |
const email = "[email protected]"; | |
function isValidEmail(input: string): input is Email { | |
return /@/.test(input); | |
} | |
function sendEmail(email: Email) { | |
console.log(email); | |
// send email | |
} | |
// sendEmail('not an email'); | |
if (isValidEmail(email)) { | |
sendEmail(email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment