function replaceKeysWithEnglishNames(obj: ContactInfo) {
const newObj = {} as ContactInfo;
for (const key in obj) {
const index = labelNames.indexOf(key);
console.log(index, key);
newObj[englishNames[index]] = obj[key] === undefined ? "" : obj[key]; // error is here
}
return newObj;
}
const labelNames: string[] = [
'Razón social de la compañía',
'RFC',
'Nombre público de la compañía (alias)',
'Nombre del contacto',
'Apellido paterno del contacto',
'Apellido materno del contacto',
'Sitio web',
'Calle de la compañía',
'Colonia',
'Municipio',
'Estado',
'País',
'Código postal',
'Correo electrónico',
'ExtNum',
'teléfono'
];
const englishNames: string[] = [
'companyName',
'rfc',
'publicName',
'contactName',
'contactLastName',
'contactSecondLastName',
'website',
'street',
'neighborhood',
'municipality',
'state',
'country',
'zipCode',
'email',
'externalNumber',
'phone'
];
/* Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'ContactInfo'.
No index signature with a parameter of type 'string' was found on type 'ContactInfo'. */
I'm kind of new with typescript, i think it is due to me going through the arrays due to the ContactInfo interface. how can I solve this?