cf.completefrontend

Predict the typesMedium

Which object literals does TypeScript reject when the target is a union?

Say every error TypeScript reports, and why line 9 behaves differently from line 5.

What does TypeScript report here?
type Shape =  | { kind: "circle"; radius: number }  | { kind: "square"; size: number }; const a: Shape = { kind: "circle", radius: 1, size: 2 }; type Loose = { radius: number } | { size: number }; const b: Loose = { radius: 1, size: 2 };const c: Loose = { radius: 1, color: "red" };

Work it out first: the compiler shows every error and type.

The answer

Work out every error TypeScript reports and every type it shows, line by line. Then check.

Checking your sign-in…