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

Which fix removes the bug?

interface User { id: number; name: string }
const u = {} as User;
console.log(u.name.length);
  1. Build a real object literal
  2. Change as User to as any
  3. Mark both fields optional
  4. Declare u with let
The assertion lies to the compiler: u.name is undefined at runtime.
Play Problem Solving ▸