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.(有没有办法实现在打字稿中。)
ask by Shubham translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…