Skip to content
Latchkey

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

  1. Provide a default with ?? or guard with a check
ts
const timeout = opts.timeout ?? 5000

Narrow with optional chaining

  1. 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

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card