Open
Description
Description
Unlike strings, array fields often contain a fixed number of elements (i.e. consider the case where the coordinates are received as an array of size 2), and I usually have to validate this manually by checking the minimum size and the maximum size simultaneously. Although this issue is easy to overcome, a more direct approach would improve readability and produce cleaner code.
Proposed solution
I propose creating the @ArraySize
decorator that validates the array's size against the provided argument
// proposed implementation
class Example {
@ArraySize(2) // accept only arrays with 2 entries
coordinates: number[];
}
// same feature with current tools
class Example {
@ArrayMinSize(2)
@ArrayMaxSize(2)
coordinates: number[]
}