Last active
April 19, 2019 15:02
-
-
Save TheCubicleBuddha/351ba1fc924923c6f54949d3f6970a03 to your computer and use it in GitHub Desktop.
This is the non-defensive implementation. To see a way to prevent possible errors, check out the defensive implementation: https://gist.github.com/TheCubicleBuddha/7a8854f244697b9894e41d44e1fc6967
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
type ITrafficLight = "red" | "green" | "yellow"; | |
// Can you see where the function below might go wrong in the future? | |
// You can skip ahead to the answer here: https://gist.github.com/TheCubicleBuddha/7a8854f244697b9894e41d44e1fc6967 | |
function respondToTrafficSignal(signal: ITrafficLight): "stop" | "go" | "pause" { | |
if(signal === "red"){ | |
return "stop"; | |
} else if(signal === "yellow"){ | |
return "pause"; | |
} else { | |
return "go"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment