zod icon indicating copy to clipboard operation
zod copied to clipboard

how can i transform class-validator + class-transfomer to zod?

Open UNDERCOVERj opened this issue 2 years ago • 1 comments

import {Type} from 'class-transfomer';
import {IsNumber} from 'class-validator';

class TestDto {
  @IsNumber()
  @Type(() => Number)
  a: number;
}

I can input { a: '123' } , and then output { a: 123 } with class-validator,although the type of a does not match,so how can I use zod to describe this case?

UNDERCOVERj avatar Jul 19 '22 02:07 UNDERCOVERj

zod.preprocess I think after reading the docs ;)

gouroujo avatar Jul 22 '22 13:07 gouroujo