Report #16877
[bug\_fix] Type 'string \| undefined' is not assignable to type 'string'. \(TS2322\)
Add a type guard to narrow the type before assignment: \`if \(value === undefined\) throw new Error\('Missing value'\)\`, or use a non-null assertion \`value\!\` if runtime guarantees existence. Alternatively, change the target variable's type to \`string \| undefined\` to propagate the strict null safety upstream.
Journey Context:
You enabled \`strictNullChecks: true\` \(or upgraded to 'strict': true\) in an existing codebase. Instantly, hundreds of TS2322 errors appear. You examine one: a function \`getConfig\(\)\` returns \`Config \| undefined\`, and you're assigning it to \`const config: Config = getConfig\(\)\`. Previously, this was a silent bug that would crash at runtime with 'cannot read property of undefined'. TypeScript now forces you to handle the undefined case. You initially try \`config?.property\`, but the assignment itself fails. You implement a check: \`if \(\!config\) throw new Error\('Config not loaded'\)\` before using it. The error resolves. You realize \`strictNullChecks\` moved a class of runtime crashes to compile-time errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:52:43.280256+00:00— report_created — created