Skip to content
Latchkey

TS2533: Object is possibly null or undefined - in CI

A value whose type includes both null and undefined was used without narrowing.

What this error means

Type-checking fails with TS2533 at access on a value typed as T | null | undefined.

tsc
src/find.ts(9,5): error TS2533: Object is possibly 'null' or 'undefined'.

Common causes

How to fix it

Narrow both cases

  1. A truthy check rules out both null and undefined for object types
ts
if (node) traverse(node)

Default with nullish coalescing

  1. Provide a fallback so the value is never null/undefined downstream
ts
const value = maybe ?? fallback

How to prevent it

  • Model nullability explicitly and narrow once at the boundary instead of repeatedly asserting.

Frequently asked questions

What causes "TS2533 null or undefined"?
Type-checking fails with TS2533 at access on a value typed as T | null | undefined.
How do I fix TS2533 null or undefined?
Narrow both cases

Related guides

References

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