Last active
May 21, 2018 16:13
-
-
Save dex4er/0cbac3a47b953775337eb0d82299ce5c to your computer and use it in GitHub Desktop.
Example from https://reasonml.github.io/ as Typescript
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
class Teacher { | |
} | |
class Director { | |
} | |
class Student { | |
constructor(name) { | |
this.name = name; | |
} | |
} | |
function greeting(stranger) { | |
if (stranger instanceof Teacher) | |
return "Hey professor!"; | |
if (stranger instanceof Director) | |
return "Hello director."; | |
if (stranger instanceof Student) { | |
if (stranger.name === "Richard") | |
return "Still here Ricky?"; | |
else | |
return "Hey, " + stranger.name + "."; | |
} | |
} |
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
class Teacher {} | |
class Director {} | |
class Student { | |
constructor (public name: string) {} | |
} | |
type SchoolPerson = Teacher | Director | Student | |
function greeting (stranger: SchoolPerson): string | void { | |
if (stranger instanceof Teacher) return "Hey professor!" | |
if (stranger instanceof Director) return "Hello director." | |
if (stranger instanceof Student) { | |
if (stranger.name === "Richard") return "Still here Ricky?" | |
else return "Hey, " + stranger.name + "." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment