An error occurred indicating that type 'number' is not assignable to type 'PersonConfig'. The issue seems to be related to the index signature in this code snippet.
interface Person {
[Id: string]: PersonConfig
}
interface PersonConfig {
name: string,
age: number
}
const people: Person[] = [
{
"p1": {
name: "abcd",
age: 20
}
},
{
"p2": {
name: "efgh",
age: 78
}
}
];
The task at hand is to add a suffix to the keys of the objects in the 'people' array (specifically, "p1" and "p2").
Expected Approach:
const suffix:string = "sub";
const people: Person[] = [
{
"p1" + suffix: {
name: "abcd",
age: 20
}
},
{
"p2" + suffix: {
name: "efgh",
age: 78
}
}
];