Related questions
How can I loop through enum values for display in radio buttons?
What is the proper way to loop through literals of an enum in TypeScript?
(I am currently using TypeScript 1.8.1.)
I've got the following enum:
export enum MotifIntervention {
Intrusion,
Identification,
AbsenceTest,
Autre
}
export class InterventionDetails implements OnInit
{
constructor(private interService: InterventionService)
{
…
Check if value exists in enum in TypeScript
I recieve a number type = 3 and have to check if it exists in this enum:
export const MESSAGE_TYPE = {
INFO: 1,
SUCCESS: 2,
WARNING: 3,
ERROR: 4,
};
The best way I found is by getting all Enum Values as an array and using indexOf …
TypeScript enum to object array
I have an enum defined this way:
export enum GoalProgressMeasurements {
Percentage = 1,
Numeric_Target = 2,
Completed_Tasks = 3,
Average_Milestone_Progress = 4,
Not_Measured = 5
}
However, I'd like it to be represented as an object array/list from our API like below:
[{id: 1, name: 'Percentage'},
{…