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
- Check for null or use optional chaining before access
ts
if (ref.current) ref.current.focus()Assert non-null only when certain
- 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
TS2531: Object is possibly null - in CIFix "error TS2531: Object is possibly 'null'" when tsc runs in CI under strictNullChecks - guard the value be…
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…
TS18049: Value is possibly null or undefined - in CIFix "error TS18049: 'x' is possibly 'null' or 'undefined'" when tsc runs in CI - narrow a T | null | undefine…