Parameter implicitly has an 'any' type
A function parameter has no type annotation, and its type cannot be inferred. This error appears when the 'noImplicitAny' compiler option is enabled.
- 1Forgetting to add a type annotation to a function parameter.
- 2The compiler is unable to infer the parameter's type from its usage within the function.
- 3Defining a function parameter without a type and without a default value.
A function parameter is missing a type annotation.
function greet(name) {
console.log("Hello, " + name);
}expected output
error TS7006: Parameter 'name' implicitly has an 'any' type.
Fix 1
Add a type annotation
WHEN The type of the parameter is known.
function greet(name: string) {
console.log("Hello, " + name);
}Why this works
Explicitly declaring the type enables type checking and improves code clarity.
Fix 2
Explicitly use 'any'
WHEN The parameter can truly be of any type and you want to be explicit about it.
function logValue(value: any) {
console.log(value);
}Why this works
Using 'any' explicitly signals that the lack of type safety is intentional.
✕ Disable 'noImplicitAny' in tsconfig.json
This is a core feature of TypeScript. Disabling it reduces type safety across the entire project.
microsoft/TypeScript src/compiler/diagnosticMessages.json
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev