swc-project / pkgs

node.js packages for SWC
62 stars 20 forks source link

@swc/jest with plainToInstance bug #52

Closed jmpark5110 closed 3 months ago

jmpark5110 commented 3 months ago

when i using @swc/jest with plainToInstance operation with @swc/jest, but ts-jest it looks fine and real runtime with swc/core it is working fine

// codes


import { Exclude, plainToInstance } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';

class SomeDto {
  @Exclude()
  id: number;

  @Exclude()
  userId: number;

  @ApiProperty()
  dataId: number;
}

const plain = {
  id: 2,
  userId: 6,
  dataId: 2900002,
};

const result = plainToInstance(SomeDto, plain);
console.log(result);
// result is
// SomeDto { id: undefined, userId: undefined, dataId: 2900002 } with @swc/jest

https://github.com/swc-project/swc/issues/2117 it is already fixed in , but i think just only remained in @swc/jest

kdy1 commented 3 months ago

See https://swc.rs/docs/migrating-from-tsc#usedefineforclassfields

jmpark5110 commented 3 months ago

See https://swc.rs/docs/migrating-from-tsc#usedefineforclassfields

ok, i resolved, thank you so much

but it need to manually add, not only applied tsconfig or jsc "target" properly, it is inteded operating?


"jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "dynamicImport": true
    },
    "target":"es2021",
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true,
      "useDefineForClassFields": false,  // add
    },
    "baseUrl": "./"
  },