TypeScript says a React parameter implicitly has an 'any' type
Parameter 'props' implicitly has an 'any' type.Short answer
TypeScript raises this error when noImplicitAny is on and it cannot infer a parameter's type. In React it means a component's props, or a handler or helper written outside JSX, has no annotation. Give props an interface, type extracted handlers with React event types, annotate standalone helpers, and type useCallback parameters.
Fix it fast
1Find out which cause you have
List every occurrence at once without writing any files, then check whether strict mode is what turns the rule on.
npx tsc --noEmit grep -n "strict\|noImplicitAny" tsconfig.json2Match what you see, then jump to its fix
- 1
The error points at the parameter list of a function component, for example function Card(props)The component takes props but never declares their typeFix - 2
The flagged parameter is named event or e, in a function declared above the return statement and passed as onChange or onClickAn event handler was moved out of the JSXFix - 3
The error is on the arrow function passed to useCallback, and tsconfig has strict set to trueA useCallback callback has an untyped parameter in strict modeFix - 4
The flagged parameter belongs to a helper such as const format = (value) => ..., not to a component or a callbackA standalone helper function that no typed API receivesFix
- 1
What does the error look like?
Parameter 'props' implicitly has an 'any' type.Parameter 'event' implicitly has an 'any' type.
Cause 1 of 4
The component takes props but never declares their type
1Check
Open the flagged line. If the parameter has no colon and no type after it, TypeScript has nothing to infer from, because nothing passes the function a type.
npx tsc --noEmit | grep "implicitly has an 'any' type"2Fix
Describe the props with an interface or type and put it on the parameter. An inline type also works for one or two fields.
interface CardProps {
title: string;
selected: boolean;
}
function Card({ title, selected }: CardProps) {
return <div aria-selected={selected}>{title}</div>;
}3Verify
Run the compiler again; the error for that component is gone.
npx tsc --noEmitConfirmed by react.dev
Cause 2 of 4
An event handler was moved out of the JSX
1Check
A handler written inline in the attribute gets its event type from the element. Once you extract it into its own function, that link is gone and the parameter is untyped.
grep -rn "function handle\|const handle" src --include=*.tsx2Fix
Annotate the parameter with the matching React event type, with the element type as the argument.
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
setName(event.currentTarget.value);
}
<input value={name} onChange={handleChange} />3Verify
The compiler accepts the handler and the attribute that receives it.
npx tsc --noEmitConfirmed by react.dev
Cause 3 of 4
A useCallback callback has an untyped parameter in strict mode
1Check
useCallback does not know which event the function will receive, so under strict mode its parameter needs a type.
grep -n "useCallback" -r src --include=*.tsx2Fix
Pass the handler type as the generic argument of useCallback, or annotate the parameter directly.
const handleChange = useCallback<React.ChangeEventHandler<HTMLInputElement>>(
(event) => {
setName(event.currentTarget.value);
},
[setName]
);3Verify
No error remains on that callback.
npx tsc --noEmitConfirmed by react.dev
Cause 4 of 4
A standalone helper function that no typed API receives
1Check
A callback passed to a typed function, such as the argument of map on a typed array, takes its parameter type from that function. A function declared on its own receives no such type, and a parameter without an annotation is implicitly any.
grep -rnE "= \(\w+\) =>" src --include=*.tsx2Fix
Write the parameter type. Turning the rule off hides this class of bug, so reserve a tsconfig override for a short migration period and fix files one by one.
const formatPrice = (value: number): string => value.toFixed(2);
// temporary, while migrating a JavaScript project (not a fix):
// "noImplicitAny": false3Verify
The compiler passes with noImplicitAny left on.
npx tsc --noEmitConfirmed by typescriptlang.org
How do I stop it coming back?
- Keep strict on from the first commit of a TypeScript project. The default for noImplicitAny is true under strict, so new untyped parameters are caught while you write them.
- Declare a Props interface next to every component before writing its body.
- Prefer inline handlers for one-line changes. Extract a handler only when you are ready to type it.
- Run tsc --noEmit in CI so an untyped parameter fails the build, not a code review.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint reports no-unused-vars for React components and imports that are used
no-unused-vars reported for a component that is rendered as a JSX tag
ESLint's core no-unused-vars does not see variables used only as JSX tags, so a component imported and rendered as <Hello /> looks unused.
3 causes, each with a fixWeb apps
TypeScript rejects MUI Data Grid columns that set a type
A TypeScript error inside a column's renderCell callback
A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.
2 causes, each with a fixWeb apps
The renderInput prop stopped working on the MUI X DatePicker
The custom TextField (variant, size, helperText) is ignored
renderInput was removed from the MUI X date pickers in version 6.
3 causes, each with a fix