TS18049: Value is possibly null or undefined - in CI
A named value typed as both null and undefined was used without narrowing either case.
What this error means
Type-checking fails with TS18049 at access on a value typed T | null | undefined.
tsc
src/node.ts(11,5): error TS18049: 'parent' is possibly 'null' or 'undefined'.Common causes
How to fix it
Truthy-guard both cases
- A truthy check rules out both null and undefined for objects
ts
if (parent) parent.append(child)Default with nullish coalescing
- Supply a fallback so downstream code sees a defined value
ts
const p = parent ?? document.bodyHow to prevent it
- Model nullability explicitly and narrow once at the boundary rather than repeatedly asserting.
Frequently asked questions
What causes "TS18049 null or undefined"?
Type-checking fails with TS18049 at access on a value typed T | null | undefined.
How do I fix TS18049 null or undefined?
Truthy-guard both cases
Related guides
TS18047: Value is possibly null - in CIFix "error TS18047: 'x' is possibly 'null'" when tsc runs in CI under strictNullChecks - guard the value befo…
TS18048: Value is possibly undefined - in CIFix "error TS18048: 'x' is possibly 'undefined'" when tsc runs in CI - narrow an optional or indexed value be…
TS2533: Object is possibly null or undefined - in CIFix "error TS2533: Object is possibly 'null' or 'undefined'" when tsc runs in CI - guard a value typed T | nu…