I'm having an issue with the following code which represents grades of students.
let students: {
[k: number]: string[]
} = {};
students[1] = ["Student 1", "Student 2"];
students[2] = ["Student 3", "Student 4"];
console.log(students);
Object.keys(students).reduce((c, v) => {
c[v] = 111; //I am assigning arbitrary values here. THIS IS WHERE THE ERROR OCCURS
return c;
}, {});
The error message I'm encountering is:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. No index signature with a parameter of type 'string' was found on type '{}'
The expected output is as follows: The value 111
is just a placeholder. There will be relevant data inserted later.
{1: 111, 2: 111}
Any help would be greatly appreciated. Thank you.