[英]How do I declare a public enum in typescript?
For the following class: 对于以下课程:
module LayoutEngine {
enum DocumentFormat {
DOCX = 1
};
export class DocHeader {
public format : DocumentFormat;
}
}
I have two questions: 我有两个问题:
thanks - dave 谢谢 - 戴夫
The above has a compile error where it says "Public property 'format' of exported class has or is using private type 'DocumentFormat'.
上面有一个编译错误,它说“导出类的公共属性'格式'已经或正在使用私有类型'DocumentFormat'。
Simply export : 只需出口:
module LayoutEngine {
export enum DocumentFormat {
DOCX = 1
};
export class DocHeader {
public format : DocumentFormat;
}
}
Is there a way to place the enum declaration inside the class?
有没有办法将枚举声明放在类中?
the enum
typescript type needs to be at a module level (a file or inside a module). enum
打字稿类型需要在模块级别(文件或模块内)。 Of course if you want it inside the class just use a json object 当然,如果你想在类中使用json对象
module LayoutEngine {
export class DocHeader {
DocumentFormat = {
DOCX: 1
};
public format : number;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.