这不可能吗?
interface IDictionary {
[index: string]: string;
}
class Dictionary implements IDictionary {
public foo = "bar";
}
相反,我得到了错误:
TS2420:Class 'Dictionary' incorrectly implements 'IDictionary'. Index signature is missing in type 'Dictionary'.
答案 0 :(得分:0)
因为你实现了一个接口
interface IDictionary {
[index: string]: string;
}
class Dictionary implements IDictionary {
public foo = "bar";
}
您需要提供所有要求
interface IDictionary {
[index: string]: string;
}
class Dictionary implements IDictionary {
public foo = "bar";
[index: string]: string;
}