📌  相关文章
📜  typescript 检查值是否在枚举中 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:20.436000             🧑  作者: Mango

代码示例1
Enum Vehicle {
    Car = 'car',
    Bike = 'bike',
    Truck = 'truck'
}

// becomes:

{
    Car: 'car',
    Bike: 'bike',
    Truck: 'truck'
}

// So you just need to do:

if (Object.values(Vehicle).includes('car')) {
    // Do stuff here
}