Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@swc/jest with plainToInstance bug #52

Closed
jmpark5110 opened this issue Aug 27, 2024 · 2 comments
Closed

@swc/jest with plainToInstance bug #52

jmpark5110 opened this issue Aug 27, 2024 · 2 comments

Comments

@jmpark5110
Copy link

jmpark5110 commented Aug 27, 2024

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
Copy link
Member

kdy1 commented Aug 27, 2024

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2024
@jmpark5110
Copy link
Author

jmpark5110 commented Aug 28, 2024

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": "./"
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants