TypeScript: error TS7006 — parameter implicitly has an 'any' type, how to fix?
Hello everyone! I recently started learning TypeScript and encountered an error I can't understand. I have a simple code for processing an array of users. I'm trying to filter active users and print their names. Here's my code:
const users = [
{ id: 1, name: 'Anna', active: true },
{ id: 2, name: 'Ivan', active: false },
{ id: 3, name: 'Maria', active: true }
];
function getActiveNames(users) {
return users
.filter(user => user.active)
.map(user => user.name);
}
const activeNames = getActiveNames(users);
console.log(activeNames);
When I run the TypeScript compiler, I get an error: TS7006: Parameter 'users' implicitly has an 'any' type. I don't understand what this means. After all, I'm passing an array of objects, and TypeScript should figure out the type of the parameter on its own. Why does this error occur and how to fix it? I've read that you can disable strict typing in tsconfig.json, but that seems wrong.
No answers yet.
Log in to leave an answer