我有一个json文件,该文件是从打字稿项目中的外部库中导入的。但是,当尝试访问json-data[config.company]
中的对象时,出现错误:
Element implicitly has an 'any' type because type '{ "company": { "delta": { "marketing": { "employee1": string; "employee2": string; }; has no index signature.ts(7017)
如何在此处为json数据声明索引签名?
图书馆
myjson.json
{
"company": {
"delta": {
"marketing": {
"employee1": "abc999",
"employee2": "abc777"
}
}
}
}
index.ts
import data = require('./src/myjson.json');
export {data};
主要项目
file.ts
import { data } from 'project/lib';
const config = {
company: argv.company as any | undefined || 'company',
};
const details = data[config.company];