I have a TypeScript project where I am trying to extract data from a properties file but it shows me the following error that I cannot resolve in the getProperty[codProduct.toUpperCase()]
code:
The element has a type "any" implicitly because the expression of type "string" cannot be used to index the type {}
This is my function:
import * as logger from 'winston';
import * as getProperty from '../json/product.json';
import { ListProductBatchModel, ResultMsg } from '../models/listProduct.models';
export class ListProductBatchUtils {
public async getDataProduct(codProduct: string): Promise<ListProductBatchModel> {
try {
let result: ResultMsg;
if (getProperty[codProduct.toUpperCase()]) {
result = {
name: getProperty[codProduct.toUpperCase()].name,
price: getProperty[codProduct.toUpperCase()].price
}
}else {
result = {
error: "ERROR"
}
}
logger.info('start')
return Promise.resolve({ resp: result });
} catch (error) {
logger.info(JSON.stringify(error));
return Promise.reject(error);
}
}
}
This is my properties file:
{
"CT": {
"name": "car",
"price": "5,00"
},
"CC": {
"name": "box",
"price": "6,00"
}
}
This is the models.ts:
interface ListProductBatchModel {
resp: ResultMsg
}
interface ResultMsg {
name?: string,
price?: string,
error?: string
}
export { ListProductBatchModel, ResultMsg };