Report #7210
[bug\_fix] Type 'string \| undefined' is not assignable to type 'string'.
Enable strictNullChecks handling by adding a type guard: 'if \(value === undefined\) throw new Error\(\)' or use the non-null assertion operator 'value\!' only if certain the value exists. The root cause is that strictNullChecks forces explicit handling of potentially null/undefined values that were previously silently allowed.
Journey Context:
A developer enables 'strict: true' in a legacy TypeScript project to improve type safety. Immediately, hundreds of errors appear. They focus on one: const userName: string = fetchUser\(\).name; where fetchUser returns \{ name: string \| undefined \}. The error reads 'Type string \| undefined is not assignable to type string'. The developer initially tries to disable strictNullChecks specifically, but their tech lead insists on keeping it enabled. They try using 'as string' casting, which works but feels wrong. They realize the API actually might return undefined for name in edge cases. They implement a proper check: const result = fetchUser\(\); if \(\!result.name\) throw new Error\('Name missing'\); const userName: string = result.name;. The error disappears. They understand that strictNullChecks caught a potential runtime bug where they were assuming data existed that might not.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:09:19.530310+00:00— report_created — created