Enums 如何在typescript中声明公共枚举?

Enums 如何在typescript中声明公共枚举?,enums,typescript,Enums,Typescript,对于以下类别: module LayoutEngine { enum DocumentFormat { DOCX = 1 }; export class DocHeader { public format : DocumentFormat; } } 我有两个问题: 上面有一个编译错误,上面写着“公共属性” 导出类的“格式”具有或正在使用私有类型 “DocumentFormat.”但在枚举之前的公共声明是 这也是一个错误。那我

对于以下类别:

module LayoutEngine {

    enum DocumentFormat {
        DOCX = 1
    };

    export class DocHeader {

        public format : DocumentFormat;
    }
}
我有两个问题:

  • 上面有一个编译错误,上面写着“公共属性” 导出类的“格式”具有或正在使用私有类型 “DocumentFormat.”但在枚举之前的公共声明是 这也是一个错误。那我该怎么做呢
  • 有没有办法将枚举声明放在类中?仅仅一个模块名并不适合名称空间,因为我在该模块中有很多类
  • 谢谢-戴夫

    上面有一个编译错误,其中显示“导出类的公共属性'format'已经或正在使用私有类型'DocumentFormat'

    简单导出:

    module LayoutEngine {
    
        export enum DocumentFormat {
            DOCX = 1
        };
    
        export class DocHeader {
    
            public format : DocumentFormat;
        }
    }
    
    有没有办法将枚举声明放在类中

    enum
    typescript类型需要位于模块级别(文件或模块内部)。当然,如果希望它位于类内部,只需使用json对象即可

    module LayoutEngine {
        export class DocHeader {
            DocumentFormat = {
                DOCX: 1
            };
    
            public format : number;
        }
    }