Common causes
- Accessing an optional property without optional chaining: obj.optionalProp without ?.value
- A function parameter is optional (name?: string) but you're using it as if it's always defined
- Array or Map access without a check — myArray[0] could be undefined if the array is empty
- A variable is declared without an initial value or initialized conditionally
How to fix it
- Add an undefined check: if (value !== undefined) { useValue(value) }
- Use optional chaining: obj.optionalProp?.nestedProp
- Provide a default value: const name = paramName ?? 'default'
- Narrow the type with a guard: if (typeof value !== 'undefined') { ... }
Example
function greet(name?: string) {
return name.toUpperCase();
// error TS2532: Object is possibly 'undefined'.
}Using an optional parameter as if it's guaranteed to be defined
Browse more errors
The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.
