Skip to content

Variable 'X' implicitly has an 'any' type

Error message

                implicitly has an 'any' type
              

Quick summary

With noImplicitAny enabled, TypeScript errors when a variable or parameter has no type annotation and its type cannot be inferred, defaulting to any.

Why this happens

  • Function parameter without a type annotation

  • Variable declared without initialization or annotation

  • Destructuring without type annotations

  • Using let without a value or type

Minimal example

✗ Broken code
function double(x) { return x * 2; } // x implicitly has any
✓ Fixed code
function double(x: number): number { return x * 2; }

Add a type annotation to the parameter x.

How to diagnose

  • Check if the variable or parameter has a type annotation

  • Check if the variable is initialized with a value (for inference)

  • Look at the error location — it names the variable

How to fix

  • Add an explicit type annotation: let x: number

  • Initialize the variable with a value: let x = 0

  • For function parameters, add type annotations

  • If any is intentional, use : any explicitly

How to prevent

  • Enable noImplicitAny (part of strict mode)

  • Always annotate function parameters

  • Initialize variables when declaring them

Related Resources

← Back to language