-
Notifications
You must be signed in to change notification settings - Fork 519
Open
Labels
status: needs triageIssues which needs to be reproduced to be verified report.Issues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.Issues describing a broken feature.
Description
Description
Passing a readonly array into plainToInstance matches the scalar overload, meaning that TS infers the result type to be a scalar, not an array. This is very dangerous as this breaks type safety and causes runtime errors
Minimal code-snippet showcasing the problem
import { IsString, validate } from "class-validator";
import { plainToClass } from "class-transformer";
class User {
@IsString()
name: string;
}
const RAW: readonly User[] = [{
name: 'Bob'
}];
const cx = plainToClass(User, RAW);Expected behavior
cx should be typed as User[]
Actual behavior
cx is typed as User
Metadata
Metadata
Assignees
Labels
status: needs triageIssues which needs to be reproduced to be verified report.Issues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.Issues describing a broken feature.