// 使用Record工具类型定义复杂数据结构的类型
type EmployeeInfo = {
name: string;
age: number;
role: string;
};
type DepartmentEmployees = Record<number, EmployeeInfo>;
type CompanyStructure = Record<string, DepartmentEmployees>;
// 编写函数
function countEligibleEmployees(structure: CompanyStructure, departmentName: string): number {
const department = structure[departmentName];
if (!department) {
return 0;
}
return Object.values(department).filter(employee => employee.age > 30 && employee.role ==='manager').length;
}