Which fix removes the bug?
interface User { name: string }
const u = {} as User;
console.log(u.name.length);
- Build a real User object
- Mark name as optional
- Add a non-null assert
- Widen User to any
The assertion only silences the compiler; at runtime
Play Problem Solving ▸
name is undefined and .length throws.