Answers for "typescript check if value is in enum"

0

typescript check if value is in enum

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
}
Posted by: Guest on July-08-2021

Code answers related to "typescript check if value is in enum"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language