【发布时间】:2021-02-23 11:56:58
【问题描述】:
我有这个代码:
function getKey(): string {
return 'foo';
}
function dummy(): void {
const object = {};
const key: string = getKey();
const value: any = 42;
object[key] = value; // ERROR: TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
}
我知道错误的存在是因为我启用了noImplicitAny 以获得更简洁的代码,但是设置此属性的简洁方法是什么?
【问题讨论】:
标签: typescript tsconfig