I am struggling with my validation not working properly when I use plainToInstance
to convert literals to classes. Although the transformation appears to be successful since I get Array(3) [Foo, Foo, Foo]
after using plainToInstance()
, the validation does not detect any errors:
Check out the Codesandbox Demo
import { plainToInstance } from 'class-transformer';
import { IsEmail, validate } from 'class-validator';
class Foo {
@IsEmail()
email: string;
}
(async () => {
const data: Foo[] = plainToInstance(Foo, [{ email: '' }, { email: '1@' }, { email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8cac9dae8ccc7c5c9c1c686cbc7c5">[email protected]</a>'}]);
// no errors
let errors = await validate(data); // no errors (errors = [])
console.info(errors);
// this errors
const foo = new Foo();
errors = await validate(foo); // errors (errors Array(1) [ValidationError])
console.info(errors);
})();
Can anyone point out what step I might be missing?