interface IObj {
fname: string;
lname: string;
}
const obj: IObj = <IObj>{};
const array: string[] = ['fname', 'lname'];
array.forEach((key: string, index: number) => {
obj[key] = `${index}`; // Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'IObj'.
});
I want to access object keys dynamically. But typescript is not letting me do it. Is there any way to achieve is in typescript.