fix: support readonly arrays

Author: WoodzCreated Nov 18, 2025Updated Nov 18, 2025
Labelstype: fixstatus: needs triage

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

typescript
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

Source: typestack/class-transformer