How to merge two enums in TypeScript

前端 未结 6 1727
無奈伤痛
無奈伤痛 2021-01-01 10:30

Suppose I have two enums as described below in Typescript, then How do I merge them

enum Mammals {
    Humans,
    Bats,
    Dolphins
}

enum Reptiles {
             


        
6条回答
  •  独厮守ぢ
    2021-01-01 11:17

    Try this enumerations example ------

    Enums or enumerations are a new data type supported in TypeScript

    enum PrintMedia {
        Newspaper = 1,
        Newsletter,
        Magazine,
        Book
    }
    
    function getMedia(mediaName: string): PrintMedia {
        if (  mediaName === 'Forbes' || mediaName === 'Outlook') {
            return PrintMedia.Magazine;
        }
     }
    
    let mediaType: PrintMedia = getMedia('Forbes');
    

提交回复
热议问题