我有以下代码:
interface IEnumElement {
elem: string;
text: string;
val: number
}
interface IIndexable<T> {
[index: string]: T;
}
class AdminBase {
ExamStatusId: IIndexable<IEnumElement> = {
All: {
elem: "",
text: 'Exam Status: All',
val: 0
},
Current: {
elem: "asdf",
text: 'Exam Status: Current',
val: 1
}
}
}
它给我一个错误说:
Error 5 Public property 'ExamStatusId' of exported class has or is
using private type 'IEnumElement'. C:\Protractor\Latest\TypeScript1.ts
答案 0 :(得分:1)
我猜一旦你开始导出AdminBase类,就会出现问题。正如在这里很好地解释:
我们要做的是导出接口
export interface IEnumElement {
elem: string;
text: string;
val: number
}
export interface IIndexable<T> {
[index: string]: T;
}
export class AdminBase {
ExamStatusId: IIndexable<IEnumElement> = {
All: {
elem: "",
text: 'Exam Status: All',
val: 0
},
Current: {
elem: "asdf",
text: 'Exam Status: Current',
val: 1
}
}
}