How to compare Enums in TypeScript

后端 未结 9 2263
攒了一身酷
攒了一身酷 2021-02-06 20:14

In TypeScript, I want to compare two variables containing enum values. Here\'s my minimal code example:

enum E {
  A,
  B
}

let e1: E = E.A
let e2: E = E.B

if (         


        
9条回答
  •  无人及你
    2021-02-06 20:33

    If was able to compare two enums with this

     if (product.ProductType && 
           (product.ProductType.toString() == ProductTypes[ProductTypes.Merchandises])) {
          // yes this item is of merchandises
      } 
    

    with ProductTypes being this export enum ProductTypes{Merchandises,Goods,...}

提交回复
热议问题