tsc · Build and types
The message
error TS7006: Parameter 'req' implicitly has an 'any' type.
What it means
The parameter has no type written on it and tsc had nothing to infer from, so it became any implicitly — which noImplicitAny treats as an error. It shows up in files ported from JavaScript and when a callback is pulled out into its own variable; by contrast, a callback written inline as items.map(x => ...) has context, so tsc infers it and this never fires. Writing the type there is the fix. You can also write any explicitly, but that is a decision to turn checking off for that parameter entirely — when you do not know what it is, unknown is more honest and forces you to narrow before use.
The fix
There is no one-line command for this. The explanation says what to look at instead.
- Printed by
- tsc
- Build and types
- 10
Build errors are a tool refusing before anything runs, so they break nothing at the moment they appear — but they do ask two questions: will you fix the type or the path to match the real shape, or will you push that one line through with an as any or a suppression comment — and it is here that the things which are only true on your own machine, letter case, extensions and environment variables, show themselves for the first time.
Reading an error message
- Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
- If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
- Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
- The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
- Before pasting a fix, check what it throws away. Some of these cannot be undone.
Common questions
Q. What does “error TS7006: Parameter 'req' implicitly has an 'any' type.” mean?
The parameter has no type written on it and tsc had nothing to infer from, so it became any implicitly — which noImplicitAny treats as an error. It shows up in files ported from JavaScript and when a callback is pulled out into its own variable; by contrast, a callback written inline as items.map(x => ...) has context, so tsc infers it and this never fires. Writing the type there is the fix. You can also write any explicitly, but that is a decision to turn checking off for that parameter entirely — when you do not know what it is, unknown is more honest and forces you to narrow before use.
Q. How do I fix it?
There is no one-line command. The explanation above says what to look at instead.
Q. Which tool prints this?
tsc. It sits under Build and types, and the message runs to 9 words.