Avatar ·

TypeScript: error "Element implicitly has an 'any' type" when accessing object by string key

Hello everyone! I'm new to TypeScript and encountered a problem that I can't solve. I'm writing a function that takes an object with user data and a string — status. I need to return an array of users with that status. Here's my code: ```typescript interface User { name: string; status: 'active' | 'inactive' | 'pending'; } const usersByStatus: Record = { active: [{ name: 'Ivan', status: 'active' }], inactive: [{ name: 'Maria', status: 'inactive' }], pending: [{ name: 'Petr', status: 'pending' }], }; function getUsersByStatus(status: string): User[] { return usersByStatus[status]; } ``` TypeScript throws an error: > Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Record