Skip to main content

TypeScript · 5 common causes

TS7006: Parameter implicitly has an 'any' type

Updated

With noImplicitAny enabled, TypeScript needs an annotation for a parameter whose type it cannot infer.

The exact message

src/form.ts:8:19 - error TS7006: Parameter 'event' implicitly has an 'any' type.

8 function onSubmit(event) {
                    ~~~~~

Found 1 error in src/form.ts:8

Paths, line numbers and stack frames differ on every machine, and the wording is tightened between versions. The part that identifies the problem is TS7006: Parameter implicitly has an 'any' type.

How to fix it

Cause 1 of 5

A standalone function's parameters are unannotated.

Annotate them: function onSubmit(event: React.FormEvent<HTMLFormElement>) {}. Contextual typing only works when the function is passed somewhere with a known signature — a function declared on its own has no context to infer from.

Cause 2 of 5

The surrounding value is untyped, so inference has nothing to flow from.

Type the source rather than the callback: declare the array as string[] and items.map(item => ...) infers item automatically. Fixing the container removes several of these errors at once.

Cause 3 of 5

A destructured parameter has no type.

The whole object needs annotating: function draw({ x, y }: { x: number; y: number }). Extract it into an interface when the shape appears more than once.

Cause 4 of 5

The library you are calling has no types.

Install @types/<package> if it exists, or write a minimal declaration for the parts you use. Annotating every call site with any spreads the untyped area through your own code instead of containing it at the boundary.

Cause 5 of 5

You have just enabled strict on a large JavaScript codebase.

Migrate in stages rather than annotating everything at once: keep "noImplicitAny": false temporarily, or put // @ts-nocheck at the top of files not yet converted. Both are debts — track them in an issue so the setting actually gets turned back on.

Stopping it coming back

Turn on strict at the start of a project, when the cost is zero, and annotate exported function signatures explicitly so inference never has to guess across a module boundary.

TS7006: Parameter implicitly has an 'any' type — common questions

Why is the same callback fine in one place and an error in another?
Contextual typing. When the callback is passed to something with a known signature, its parameters are inferred; when it is declared standalone and passed later, there is nothing to infer from at the point of declaration.
Is annotating with any acceptable to move on?
It compiles, but it silently disables checking for every use of that value. unknown is the better placeholder — it also compiles, and it forces a check before use, so the compiler keeps helping you.
Should I use noImplicitAny without full strict?
You can, and it is the single most valuable of the strict family. But strictNullChecks catches a whole class of runtime crashes, so treat noImplicitAny as the first step towards strict rather than the destination.

Test the fix before you paste it back

Reproducing the failure in a scratch file is usually faster than editing the real one. AltF Code is a free in-browser editor with real syntax highlighting for HTML, CSS, JavaScript, TypeScript, Python, SQL and JSON, and it runs HTML, CSS and JavaScript live in a preview panel. No install and no sign-up.

Open the editor