Report #48029
[bug\_fix] TS2322: Type 'string \| undefined' is not assignable to type 'string'.
Use a type guard \(e.g., \`if \(value \!== undefined\)\`\) to narrow the type, provide a default value, or use the non-null assertion operator \`\!\` if certainty exists. Root cause: With \`strictNullChecks\` enabled, TypeScript enforces that potentially undefined values cannot be assigned to non-nullable types without explicit verification or handling.
Journey Context:
Developer has \`strict: true\` enabled. They parse a URL parameter: \`const id = searchParams.get\('id'\)\`. They know this route always has the ID, so they immediately write \`const numericId: number = parseInt\(id, 10\)\`. TypeScript throws TS2322: Type 'string \| null' is not assignable to type 'string'. The developer tries to fix it by checking \`if \(id\)\`, but TypeScript still complains because \`id\` could be an empty string, not just null. They realize they need to check \`if \(id \!== null\)\` or \`if \(typeof id === 'string'\)\`. After the check, the type is narrowed to \`string\` and the code compiles. Alternatively, if they are certain, they might use \`id\!\` but learn that's unsafe. This pattern repeats when dealing with JSON parsing, database results, or optional chaining results.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T11:05:57.949421+00:00— report_created — created