检查枚举是否包含值的类型描述

2022-05-07

以下示例是关于Typescript中包含检查枚举是否包含值的类型描述用法的示例代码,想了解检查枚举是否包含值的类型描述的具体用法?检查枚举是否包含值的类型描述怎么用?检查枚举是否包含值的类型描述使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

[英]:check if enum contains value typescript源码类型:Typescript
enum EList {
  ITEM_FOO = 'fooData',
  ITEM_BAR = 'barData'
}

const lookingForKey = 'ITEM_BAR'
const lookingForValue = 'barData'

// test if `lookingForKey` exists within `EList`
console.log(Object.keys(EList).some((v) => v === lookingForKey))

// test if `lookingForValue` exists within `EList`
console.log(Object.values(EList).some((v) => v === lookingForValue))

本文地址:https://www.itbaoku.cn/snippets/785325.html