我想在TypeScript中创建一个字典中的每个元素都是类类型的字典。TypeScript创建一个类型的字典
interface Methods {
[index: string]: MethodRep;
}
export class MethodRep {
name: string;
}
export class BaseFileStructure {
public methods: Methods;
constructor() {
this.methods = {};
}
}
但它似乎并不喜欢它。我使用原子与TypeScript插件。它说Compile failed but emit succeeded
。
如果我改变元素的字符串,然后它工作(即使把型号不工作)
interface Methods {
[index: string]: string; // only this works
}
什么我在这里失踪的类型?
Typescript playground(http://www.typescriptlang.org/Playground)不会为您的代码显示任何错误。 – TSV
您是否尝试将您的MethodRep类更改为接口? – Guillaume
同意@Guillaume我只有这样才能使用接口 – gsobocinski