TS2411
Property 'age' of type 'number' is not assignable to 'string' index type 'string'.
Broken Code ❌
interface Person {
[key: string]: string;
age: number;
name: string;
}Fixed Code ✔️
We defined an interface where every key has a value of type string. This doesn't work for age which is why we have to extend the possible value types using a union type:
interface Person {
[key: string]: number | string;
age: number;
name: string;
}