TS7022
TypeScriptERRORNotableStrictHIGH confidence

'X' implicitly has type 'any' because it does not have a type annotation and ...

Production Risk

Build will fail; resolve before shipping.

What this means

A strict mode error (TS7022): 'X' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.. This diagnostic is emitted by the TypeScript compiler when 'X' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer..

Why it happens
  1. 1TypeScript cannot infer the type and defaults to 'any' with --noImplicitAny
  2. 2Missing type annotation or type parameter
How to reproduce

TypeScript compiler reports TS7022 during type checking.

trigger — this will error
trigger — this will error
// Triggers TS7022
// 'X' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

expected output

error TS7022: 'X' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Fix

Add an explicit type annotation

WHEN When TypeScript cannot infer the type

Add an explicit type annotation
// Before (implicit any)
function process(value) { return value; }
// After (explicit type)
function process(value: string): string { return value; }

Why this works

Adding explicit type annotations removes the implicit 'any' and enables full type checking.

What not to do

Suppress with @ts-ignore instead of fixing the type

ts-ignore hides real type errors and makes refactoring unsafe.

Sources
Official documentation ↗

TypeScript Compiler Diagnostics

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All TypeScript errors