fix: Uint8Array are not being filled in plainToClassFromExist

Author: vladbarceloCreated Mar 11, 2025Updated Sep 3, 2025
Labelstype: fixstatus: needs triage

Description

Using plainToClassFromExist on classes with properties of type Uint8Array leads to data loss - the properties in the resulting class contain empty arrays.

Minimal code-snippet showcasing the problem

typescript
import { plainToClassFromExist, Type } from 'class-transformer';

class SomeClass {
  @Type(() => Uint8Array)
  public arr: Uint8Array;
}

const raw: SomeClass = {
  arr: new Uint8Array([1, 2, 3]),
};

console.log(raw, plainToClassFromExist(SomeClass, raw));

Expected behavior

{ arr: Uint8Array(3) [ 1, 2, 3 ] } [class SomeClass] { arr: Uint8Array(3) [ 1, 2, 3 ] }

Actual behavior

{ arr: Uint8Array(3) [ 1, 2, 3 ] } [class SomeClass] { arr: Uint8Array(0) [] }
                                                                       ^ data being lost

Source: typestack/class-transformer