如何在打字机中声明公开的枚举? [英] How do I declare a public enum in typescript?
本文介绍了如何在打字机中声明公开的枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于以下类:
module LayoutEngine {
enum DocumentFormat {
DOCX = 1
};
export class DocHeader {
public format : DocumentFormat;
}
}
我有两个问题:
- 上面有一个编译错误,它表示公共属性
格式的导出类有或正在使用私有类型
'DocumentFormat 。但在枚举之前的公开声明是
也是一个错误。那么我该怎么做? - 有没有办法将枚举声明放在课堂里?只有模块名称对于命名空间并不好,因为我在该模块中有很多类。
谢谢 - dave
thanks - dave
推荐答案
上面有一个编译错误,它表示公共属性格式的导出类有或是使用私人类型DocumentFormat。
The above has a compile error where it says "Public property 'format' of exported class has or is using private type 'DocumentFormat'.
只需导出:
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?
枚举
typescript类型需要在一个模块级别(一个文件或模块内)当然如果你想要在类中只使用一个json对象
the enum
typescript type needs to be at a module level (a file or inside a module). Of course if you want it inside the class just use a json object
module LayoutEngine {
export class DocHeader {
DocumentFormat = {
DOCX: 1
};
public format : number;
}
}
这篇关于如何在打字机中声明公开的枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文