import { registerDecorator , ValidationOptions , ValidatorConstraint , ValidatorConstraintInterface , ValidationArguments , isString , } from 'class-validator' ; import { isNil } from 'lodash' ; @ ValidatorConstraint ( { async : true } ) class IsNilOrStringConstraint implements ValidatorConstraintInterface { validate ( value , _args ) { return isNil ( value ) || isString ( value ) ; } } export function IsNilOrString ( validationOptions ? ) { return function ( object , propertyName ) { registerDecorator ( { target : object . constructor , propertyName : propertyName , options : validationOptions , constraints : [ ] , validator : IsNilOrStringConstraint , } ) ; } ; }