【发布时间】:2019-07-09 07:13:19
【问题描述】:
我想使用以下enum 的值:
export enum GenFormats {
SHORT_LOWER = 'm/f', SHORT_UPPER = 'M/F', FULL = 'Male/Female'
};
如下所示:
export interface IGenderOptions {
format: 'm/f' | 'M/F' | 'Male/Female'
};
通过使用类型提取/定义,例如:
{{some type cast/logic}}<GenFormats> // Outputs: 'm/f' | 'M/F' | 'Male/Female'
更新问题:
这是我的代码:
export enum EGenderFormats {
SHORT_LOWER = 'm/f', SHORT_UPPER = 'M/F', FULL = 'Male/Female'
};
export interface IGenderFormats {
SHORT_LOWER: 'm/f'; SHORT_UPPER: 'M/F'; FULL: 'Male/Female';
};
export interface IGenderOptions {
format: IGenderFormats[keyof IGenderFormats]
};
const DEFAULTS: IGenderOptions = {
format: EGenderFormats.FULL
};
我的问题是,我如何使用单个实体 enum EGenderFormats 或 interface IGenderFormats 而不是两者?
我正在使用 Typescript 3.2.2
谢谢
【问题讨论】:
-
能否请您在 stackblitz 上发布您的代码并详细说明您的问题?
-
@dileepkumar jami,我已经提供了尽可能多的描述。
-
@jcalz ,我更新了我的问题,请帮忙。
标签: typescript typescript-typings typescript3.0