栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

打字稿枚举的构造函数?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

打字稿枚举的构造函数?

Typescript不支持诸如Java中的扩展枚举。您可以使用一个类实现类似的效果:

interface EnumIdentity { }class Status implements EnumIdentity {    private static AllValues: { [name: string] : Status } = {};    static readonly Active = new Status(1, "Active");    static readonly AwaitingReview = new Status(2, "Awaiting Review");    static readonly Closed = new Status(3, "Closed");    static readonly Complete = new Status(4, "Complete");    static readonly Draft = new Status(5, "Draft");    static readonly InProcess = new Status(6, "In Process");    static readonly InReview = new Status(7, "In Review");    static readonly NotStarted = new Status(8, "Not Started");    static readonly PendingResolution = new Status(9, "Pending Resolution");    static readonly Rejected = new Status(10, "Rejected");    private constructor(public readonly id: number, public readonly displayValue: string) {        Status.AllValues[displayValue] = this;    }    public static parseEnum(data: string) : Status{        return Status.AllValues[data];    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454440.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号