繁体   English   中英

在Typescript界面​​中使用枚举的任何值

[英]Use any value of an enum in a Typescript interface

我有一个Typescript界面

export interface MyInterface {
  valid: boolean;
  resourceType: MyEnum;
  message: string;
}

和一个枚举

enum MyEnum {
  'a',
  'b',
  'c'
}

是否可以允许MyInterface.resourceType的值是MyEnum中的任何值?

目前我的IDE抛出错误

property 'resourceType' of exported interface has or is using private 
name 'MyEnum'

尝试导出枚举

export enum MyEnum {
  a = 'a',
  b = 'b',
  c = 'c'
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM