Skip to content

fix: Uint8Array are not being filled in plainToClassFromExist #1815

Open
@vladbarcelo

Description

@vladbarcelo

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions