The code in my service.ts file is :-
import {injectable} from '@angular/core';
export class ConstantService{
constructor(){}
public enumTemp = {
one:'this is one',
two:'this is two',
three:'this is three'
}
public GetenumTempMapping(colname: string){
let keys = Object.keys(this.enumTemp);
let key=keys.find((i:any) => {
return i == colname;
}
return this.enumTemp[key];
}
}
I want to pass a string "one" into the function GetenumTempMapping and get the value 'this is one' but for this function is throwing the error in the return statement saying that element implicitly has 'any' type because expression of type string can't be used to index. What am i doing wrong?
Edit:
adding :any to the declaration of enumTemp solved the issue( public enumTemp:any = {one:'one is one'} ). But I think the better way is to add a interface please refer this: For interface implementation provided by @ruth in the comments