feature: Enhance Message Support for Array Input in @IsEnum() Decorator #2536
Labels
flag: needs discussion
Issues which needs discussion before implementation.
type: feature
Issues related to new features.
Context
The
@IsEnum()
decorator in class-validator is officially designed to accept an enum object, ensuring that the validated value is part of a specified TypeScript enum like this:However, many users unofficially use arrays as an alternative to enums when working with this decorator like this:
Problem
When passing an array directly to @IsEnum(), the default error messages get truncated or don't display the expected values correctly. Specifically, the
$constraint2
placeholder does not behave as intended, causing incomplete or incorrect validation messages.Proposed Feature
Rather than considering this a bug, it would be better to officially support arrays as valid input for the @IsEnum() decorator. This would allow developers to pass arrays of valid values, and the decorator would handle them as enums internally, without causing issues with error messages. This would also align with how many developers are already using this decorator in their projects.
The text was updated successfully, but these errors were encountered: