Before Angular 12, this functioned properly:
export interface Content {
categories: string[]
concepts: Topic[]
formulas: Topic[]
guides: Topic[]
}
//this.content is of type Content
['formulas', 'concepts'].forEach(c => {
this.content[c].forEach(topic => {
//....
});
})
However, it now triggers an error (For the line this.content[c]
):
An 'any' type is implicitly related to 'Element' because an expression of type 'string' cannot be used to index type 'Content'. No index signature with a parameter of type 'string' was found on type 'Content'.ts(7053)
How can I inform Typescript that this.content[c]
is an array containing instances of Topic
?