← 문제 목록
중급
TypeScript
50P
판별 유니온 타입 오류
다음 TypeScript 코드에서 버그를 찾으세요:
TYPESCRIPT
interface Circle {
kind: "circle";
radius: number;
}
interface Square {
kind: "square";
sideLength: number;
}
type Shape = Circle | Square;
function getArea(shape: Shape): number {
switch (shape.kind) {
case "circle":
return Math.PI * shape.radius ** 2;
case "square":
return shape.sideLength ** 2;
case "triangle":
return 0;
}
}
0명 풀이 · 정답률 0%