TS18048: Value is possibly undefined - in CI
A named value that can be undefined was used without first checking it.
What this error means
Type-checking fails with TS18048 naming an optional property or indexed access used unguarded.
tsc
src/cfg.ts(5,3): error TS18048: 'opts.timeout' is possibly 'undefined'.Common causes
How to fix it
Default or guard the value
- Provide a default with ?? or guard with a check
ts
const timeout = opts.timeout ?? 5000Narrow with optional chaining
- Chain access so undefined short-circuits
ts
opts.signal?.addEventListener("abort", onAbort)How to prevent it
- Handle optional and indexed values with defaults or guards; noUncheckedIndexedAccess surfaces these early.
Frequently asked questions
What causes "TS18048 possibly undefined"?
Type-checking fails with TS18048 naming an optional property or indexed access used unguarded.
How do I fix TS18048 possibly undefined?
Default or guard the value
Related guides
TS2532: Object is possibly undefined - in CIFix "error TS2532: Object is possibly 'undefined'" when tsc runs in CI - guard array/optional access before u…
TS18047: Value is possibly null - in CIFix "error TS18047: 'x' is possibly 'null'" when tsc runs in CI under strictNullChecks - guard the value befo…
TS18049: Value is possibly null or undefined - in CIFix "error TS18049: 'x' is possibly 'null' or 'undefined'" when tsc runs in CI - narrow a T | null | undefine…