What is the correct fix?
type Cfg = { a: number } | { b: number };
function read(c: Cfg) {
return c.a;
}
- Narrow it:
if ('a' in c) return c.a; - Narrow it:
if (c.a) return c.a;first - Change the union into an intersection
- Mark both members of the union optional
Only properties common to every union member are accessible until the type is narrowed.
Play Problem Solving ▸