The following abstracted TS scenario:
interface EmotionsOkay {
emotion: string;
okay: "yap";
}
interface EmotionsNotOkay {
emotion: string;
}
type UndetereminedEmotion = EmotionsOkay | EmotionsNotOkay;
const areYouOkay = (test: UndetereminedEmotion) => {
console.log(test.okay ? "happy :D" : "sad D:");
};
throws a TypeScript error when console logging test.okay
, because it apparently does not exist.
Property `okay` does not exist on type `UndetereminedEmotion`.
Even though it could very well exist, if the test passed to the method was of type EmotionsOkay
.
Why does this happen?