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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →