When I tried to use the IsEnum class validator in the code snippet below:
export class UpdateEvaluationModelForReportChanges {
@IsNotEmpty()
@IsEnum(ReportOperationEnum) // FIRST
operation: ReportOperationEnum;
@IsNotEmpty()
@IsEnum(EvaluationStatusEnum). // SECOND
status: EvaluationStatusEnum;
// ...
}
I encountered an error with the second IsEnum decorator:
../node_modules/src/decorator/typechecker/IsEnum.ts:18
return Object.entries(entity)
^
TypeError: Cannot convert undefined or null to object
The first enum, ReportOperationEnum
, is defined in the same file as the class. Here is its definition:
// ...
export enum ReportOperationEnum {
COMPLETED = "COMPLETED",
REVIEWED = "REVIEWED",
RETURNED = "RETURNED",
}
// ...
The second enum, EvaluationStatusEnum
, is in a separate file:
// ...
export enum EvaluationStatusEnum {
CANCELED = 'CANCELED',
SCHEDULED = 'SCHEDULED',
FINISHED = 'FINISHED',
}
// ...
Merging the second enum into the file with the first enum solves the issue, but I would like to avoid duplicating or moving the second enum from its original location. Both enums are part of files that contain other enums and classes. Could there be any reasons or factors causing this problem?