Skip to content
Latchkey

TS18047: Value is possibly null - in CI

A named value whose type includes null was used without ruling null out first.

What this error means

Type-checking fails with TS18047 naming the value that may be null at the use site.

tsc
src/ref.ts(8,3): error TS18047: 'ref.current' is possibly 'null'.

Common causes

How to fix it

Guard or optional-chain

  1. Check for null or use optional chaining before access
ts
if (ref.current) ref.current.focus()

Assert non-null only when certain

  1. Use ! solely when you can guarantee the value is set
ts
ref.current!.focus()

How to prevent it

  • Guard nullable values explicitly; reserve the non-null assertion for genuinely guaranteed cases.

Frequently asked questions

What causes "TS18047 possibly null"?
Type-checking fails with TS18047 naming the value that may be null at the use site.
How do I fix TS18047 possibly null?
Guard or optional-chain

Related guides

References

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