interface type {
id: number;
name: string;
}
const formFields: (keyof type)[] = ['id','name']
let test: type = {
id: 0,
name: `name`
}
let data: string[] = ['1','Name']
for(let i = 0 ; i < data.length ; i++){
const field = formFields[i];
if (typeof test[field] === 'number'){
test[field] = Number(data[i]);
}else if(typeof test[field] === 'string'){
test[field] = data[i];
}
}
I want to dynamically modify values in the object, but I can’t avoid this error, although it doesn’t affect the actual operation.
New contributor
ZVMAGL3 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.