Typescript根据条件导出枚举? [英] Typescript Export enum based on the condition?

查看:74
本文介绍了Typescript根据条件导出枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于环境的角度我需要导出枚举.我不知道它是否正确吗?role.ts

Angular based on the environment I need to export enum. I don't know wether it is correct or not? role.ts

import { environment } from '../../environments/environment';
if(environment.production) {
  export enum Role {
   User: 'user',
   Admin: 'admin'
  }
 } else {
  export enum Role {
   User: 'user',
   Admin: 'user'
  }
}

基于条件如何导出呢?谢谢

Based on the condidtion how to export it? Thanks

推荐答案

您可以这样做:

import { environment } from '../../environments/environment';
export class Role {
  static User = 'user';
  static Role = (environment.production) ? 'role' : 'admin';
}

这篇关于Typescript根据条件导出枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆