Skip to content

Class transformer not working with swc #2117

@DanielRamosAcosta

Description

@DanielRamosAcosta

Describe the bug

When applying the plainToClass function to a class defined with class-validator, it returns the class with no attributes

Input code

Here is a repo with a test reproducing the error

const usersOptionsInput = plainToClass(GetUsersOptionsInput, {
  query: "Query",
  pagination: { skip: 0, limit: 20 },
});

expect(usersOptionsInput.query).toEqual("Query"); // error

Config

You can also find the config at the repo reproducing the error

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "target": "es2018"
  },
  "module": {
    "type": "commonjs",
    "noInterop": true
  }
}

Expected behavior
I would expect the instance of the class to have all the defined attributes.

Version
The version of @swc/core: 1.2.80

Additional context

Just one more time, I created this repo in order to reproduce the error

This error is related to #1362

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions