InCompatibleWith is a decorator for class-validator that checks if siblings are not exist on object.
npm i incompatiblewith
@IncompatibleWith accepts an array of siblings name in string.
@IncompatibleWith (siblingPropsName: string[])
InCompatibleWith checks if other properties exist on an object or not.
In this case we want to have either status
or deleted
on the instance of class. If both exist it will complain.
import { IncompatibleWith } from 'incompatiblewith';
class UpdateUserDTO {
@IsString()
@IncompatibleWith(['deleted'])
readonly status: string;
@IsBoolean()
@IncompatibleWith(['status'])
readonly deleted: boolean;
@IsString()
readonly name: string;
}
const obj = {
status: 'test',
deleted: true,
name: 'john',
};
const obj = {
deleted: true,
name: 'john',
};
Or
const obj = {
status: 'test',
name: 'john',
};