When things come to Javascript updating an object is something is like following.
const data = {
a: 1,
b: 3,
c: 4
}
const update = (summary) => {
data[summary] += 1;
console.log(data);
}
update('a');
I tried the same thing with Typescript but it doesn't work as such I know I'm doing something wrong can someone point out the faults and how to work things out.
interface Summary {
a: number,
b: number,
c: number
}
const data: Summary = {
a: 1,
b: 3,
c: 4
}
const updateData = (summaryType: string) => {
data[summaryType] += 1 // Error
}
The Error is -> Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Summary'. No index signature with a parameter of type 'string' was found on type 'Summary'.(7053)