TypeScript
TypeScript parameter implicitly has an any type
TypeScript reported a function parameter with no explicit type and no safe inference under noImplicitAny rules.
TypeScript
TypeScript reported a function parameter with no explicit type and no safe inference under noImplicitAny rules.
Observed message
error TS7006: Parameter 'X' implicitly has an 'any' type.
Why it happens
How to fix it
function greet(name) {
return name.toUpperCase();
}
greet("Ada");function greet(name: string) {
return name.toUpperCase();
}
greet("Ada");With noImplicitAny, the first function reports TS7006. A later call does not infer the declaration parameter type. The corrected example compiles and returns ADA. This pattern works in current TypeScript 5.x and 6.x.
const format = (name) => name.toUpperCase();const names: string[] = ["Ada"];
const upper = names.map(name => name.toUpperCase());The standalone callback has no contextual parameter type. map on string[] supplies string automatically, so the corrected example needs no explicit parameter annotation.
Official reference
TypeScript TSConfig: noImplicitAnyRelated errors
Explore more