Recently, the enum in my jhipster project went through a change. It was originally defined like this:
export enum DeclarationStatus {
NEW = 'NEW',
DRAFT = 'DRAFT',
APPROVED_BY_FREELANCER = 'APPROVED_BY_FREELANCER',
APPROVED_BY_CLIENT = 'APPROVED_BY_CLIENT',
APPROVED = 'APPROVED'
}
and then changed to this:
export enum DeclarationStatus {
NEW,
DRAFT,
APPROVED_BY_FREELANCER,
APPROVED_BY_CLIENT,
APPROVED
}
Initially, I could compare the status like this:
status === DeclarationStatus.APPROVED_BY_FREELANCER;
However, with the new change, that approach no longer works as the enum is now assigned numbers. The following comparison does produce the desired result:
DeclarationStatus[''+status] === DeclarationStatus.APPROVED_BY_FREELANCER;
Hence, my question is which method is better or if there might be a third alternative?
I marked this question as answered because the Jhipster community reverted the change back to the original state. This made the comparisons easier once again.
A special thank you to @vicpermir for facilitating this solution.