Decorator | Type | Description |
---|---|---|
@IsNullableString | string | null |
@IsUndefinableString | string | undefined |
@IsOptionalString | string | null |
@IsNotEmptyNumberString | string | Checks a string is a number |
@IsNotEmptyBooleanString | string | Checks a string is a boolean |
@IsNullableNumberString | string | null |
@IsNullableBooleanString | string | null |
@IsUndefinableNumberString | string | undefined |
@IsUndefinableBooleanString | string | undefined |
@IsOptionalNumberString | string | null |
@IsOptionalBooleanString | string | null |
Decorator | Type |
---|---|
@IsNotEmptyNumber | number |
@IsNullableNumber | nubmer |
@IsUndefinableNumber | number |
@IsOptionalNumber | number |
Decorator | Type |
---|---|
@IsNotEmptyBoolean | boolean |
@IsNullableBoolean | boolean |
@IsUndefinalbeBoolean | boolean |
@IsOptionalBoolean | boolean |
import { isNotEmptyString, IsNotEmptyBoolean, isNullable, IsUndefinable } from 'custom-class-validator-tools';
import { IsInstance, ArrayNotEmpty, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
class Tag {
@IsNotEmptyString()
tag1: string;
@IsNotEmptyString()
tag2: string;
}
class Result {
@IsNotEmptyBoolean()
failed: boolean;
}
class Post {
@IsNullable()
@ArrayNotEmpty()
@IsInstance(Tag, { each: true })
@ValidateNested({ each: true })
@Type(() => Tag)
tags: Tag[] | null;
@IsUndefinable()
@IsInstance(Result)
@ValidateNested()
@Type(() => Result)
result?: Result;
}