#class-validator

7 messages · Page 1 of 1 (latest)

obtuse oxide
#
import { IsDefined, Max, MaxLength, Min, MinLength } from 'class-validator';

class UserDto {
  @MinLength(2)
  @MaxLength(10)
  public readonly nickname: string;

  @Min(1)
  @Max(100)
  public readonly age: number;
}

class CreateUserDto extends UserDto{} // I want nickname and age to be required in this class
class UpdateUserDto extends UserDto{}  // I want nickname and age to be optional in this class

Is there any way to achieve this without repeating the same code three times?

worldly prism
#

it should work without needing to do anything extra

#

doesn't it?

#

since the fields are inherited and the decorators are related to those fields

#

@obtuse oxide

obtuse oxide
#

thx