$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #123

What is the correct fix?

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