I am not assigning new property like this:Typescript error: TS7053 Element implicitly has an 'any' type Hence any would not work. I am just trying to edit an existing proprety based on an interface
updateFieldTest(index: number, field: string ) {
const tasks: Foo[] = [
{foo:1,bar:2},
{foo:1,bar:2},
{foo:1,bar:2},
{foo:1,bar:2},
]
const task = tasks[index];
task[field] = 4
}
The interface Foo
export interface Foo {
foo: number,
bar: number
}
Gives this error
ERROR in src/app/app.component.ts(391,9): error TS7017: Element implicitly has an 'any' type because type 'Foo' has no index signature
As temporary solution, changed field: string
to field: 'foo' | 'bar'
But is there a better way?