Home › JavaScript

TS7006: Parameter 'x' implicitly has an 'any' type. (TypeScript) — how to fix

src/utils.ts:3:22 - error TS7006: Parameter 'value' implicitly has an 'any' type.

3 export function format(value) {
                         ~~~~~

Quick fix: Add a type annotation: function format(value: string). For callbacks and event handlers, type the variable or use the right event type ((e: React.ChangeEvent<HTMLInputElement>) => ...). For destructured params, annotate the whole object: ({ id, name }: Props). Use unknown rather than any if the type is truly unknown.

What it means

TypeScript infers most types, but it can't infer a function parameter from nothing:

function format(value) {        // what is value?
  return value.toFixed(2);
}

Without noImplicitAny, value would silently become any and lose all type checking. With it (and "strict": true turns it on), TypeScript reports TS7006 instead. The fix is to say what the parameter is.

Fix 1: annotate the parameter

function format(value: number): string {
  return value.toFixed(2);
}

const add = (a: number, b: number) => a + b;

Optional and default parameters:

function greet(name?: string) { /* ... */ }
function retry(times = 3) { /* number, inferred from the default */ }

Fix 2: destructured parameters

Annotate the whole pattern, not each name. ({ id: number }) would rename id to a variable called number:

type Props = { id: number; name: string };

function User({ id, name }: Props) { /* ... */ }

Fix 3: callbacks get their type from context

Inline callbacks are inferred from the function they're passed to:

[1, 2, 3].map(n => n * 2);          // n: number, no error

The error appears when the callback is defined separately, or passed to something typed as any:

const double = n => n * 2;          // TS7006: no context
const double = (n: number) => n * 2;

Typing the variable works too:

const onDone: (result: string) => void = result => console.log(result);

Fix 4: React event handlers

Handlers defined outside the JSX have no context. Use React's event types:

function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
  setText(e.target.value);
}

function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
  e.preventDefault();
}

const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => { /* ... */ };

Or write the handler inline (onChange={e => setText(e.target.value)}) and the type is inferred.

Fix 5: the type really is unknown

Prefer unknown over any: it forces you to narrow before use.

function log(data: unknown) {
  if (typeof data === 'string') console.log(data.toUpperCase());
}

Use an explicit any only as a deliberate escape hatch: (x: any) silences TS7006 for that parameter.

Fix 6: JavaScript files with checkJs

In .js files checked by TypeScript (checkJs or // @ts-check), annotate with JSDoc:

/**
 * @param {number} value
 * @returns {string}
 */
function format(value) {
  return value.toFixed(2);
}

Turning it off

While migrating a JavaScript codebase you can disable the check in tsconfig.json:

{ "compilerOptions": { "strict": true, "noImplicitAny": false } }

This keeps the other strict checks. Treat it as temporary: every unannotated parameter becomes any and errors that TypeScript could catch go unnoticed.

Last updated 2026-11-30.