Created
January 18, 2021 05:01
-
-
Save hw0k/dfa81575d24fa231a753172e58446750 to your computer and use it in GitHub Desktop.
TN 5
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 Person { | |
play: () => void; | |
sing: () => void; | |
talk: () => void; | |
} | |
function playWithPerson(person: Person | undefined) { | |
if (!person) { | |
// person은 undefined로 추론됨. | |
throw new Error('Person not found!'); | |
} | |
// person은 Person으로 추론됨. | |
person.play(); | |
} | |
function singWithPerson(person: Person | null) { | |
if (!person) { | |
// person은 null로 추론됨. | |
throw new Error('Person not found!'); | |
} | |
// person은 Person으로 추론됨. | |
person.sing(); | |
} | |
function talkWithPerson(person: Person | undefined | null) { | |
if (!person) { | |
// person은 undefined | null로 추론됨. | |
throw new Error('Person not found!'); | |
} | |
// person은 Person으로 추론됨. | |
person.talk(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment