How to Fix No index signature with a parameter of type 'string' issue in Angular
Getting ESLint error here : Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Client'. No index signature with a parameter of type 'string' was found on type 'Row'
dynamic-table.component.html
<table>
<tr>
<th *ngFor="let i of headers">
{{i.name}}
</th>
</tr>
<tr *ngFor="let row of rows">
<td *ngFor="let head of headers">
{{row[head.name]}} <!-- Getting ESLint error here : Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Client'.
No index signature with a parameter of type 'string' was found on type 'Row'. -->
</td>
</tr>
</table>
dynamic-table.component.ts
interface Header {
displayName: string,
name: string
}
interface Row {
empId: string,
empName: string,
salary: string
}
@Component({
selector: "dynamic-table",
templateUrl: "./dynamic-table.component.html",
styleUrls: []
})
export class DynamicTableComponent {
title = "Dynamic Table";
headers: Header[] = [];
rows: Row[] = [];
constructor() {
this.headers = [
{
displayName: "Emp Name",
name: "empName"
},
{
displayName: "Emp ID",
name: "empId"
},
{
displayName: "Salary",
name: "salary"
}
];
this.rows = [
{
empId: "1",
empName: "red",
salary: "10000"
},
{
empId: "1",
empName: "red",
salary: "50000"
},
{
empId: "1",
empName: "red",
salary: "30000"
}
];
}
}