Code QuizAdvanced

Wrong Property in Union Branch

A discriminated union narrows correctly but the circle branch reads the wrong property.

Codetypescript
type Circle = { kind: "circle"; radius: number };
type Square = { kind: "square"; side: number };
type Shape = Circle | Square;

function area(shape: Shape): number {
  if (shape.kind === "circle") {
    return shape.side * shape.side;
  }
  return shape.side * shape.side;
}

What is wrong with the circle branch?

Watch the code walkthrough

Watch on YouTube →