Created
January 17, 2021 09:32
-
-
Save hw0k/fcd5d476ba340b48482a9fe3a13cd626 to your computer and use it in GitHub Desktop.
TN 2
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
function sound(animal: Dog | Cat) { | |
if (animal instanceof Dog) { | |
// animal은 Dog로 추론됨. | |
animal.bark(); | |
animal.meow(); // error TS2339: Property 'meow' does not exist on type 'Dog'. | |
return; | |
} | |
if (animal instanceof Cat) { | |
// animal은 Cat으로 추론됨. | |
animal.bark(); // error TS2339: Property 'bark' does not exist on type 'Cat'. | |
animal.meow(); | |
return; | |
} | |
// animal은 never로 추론됨. | |
animal.bark(); // error TS2339: Property 'bark' does not exist on type 'never'. | |
animal.meow(); // error TS2339: Property 'meow' does not exist on type 'never'. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment