-
-
Save fujimura/aca7b841fab0f344e76343ba3c1d86a5 to your computer and use it in GitHub Desktop.
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
// @flow | |
type A = { | |
x: number, | |
y: number, | |
type: "A" | |
}; | |
type B = { | |
x: number, | |
type: "B" | |
}; | |
type X = A | B; | |
const f = (x: X): number => { | |
if (x.type === "A") { | |
return x.y; | |
} else if (x.type === "B") { | |
return x.x; | |
} else if (x.type === "C") { | |
// これは型エラーになって欲しい | |
return x.z; | |
} else { | |
return 0; | |
} | |
}; | |
console.log(f({ type: "B", x: 1 })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment