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

fix(swc): don't set missing class fields #2155

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

rickdgeerling
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

SWC adopts ESNext behaviour of explicitly setting fields as undefined by default. Disabling this behaviour aligns better with TS that targets ES2021.

The result is as following:

import { plainToInstance } from "class-transformer";

class SomeClass {
  public aNumber: number;
  public aString: string;
}

const partialA = plainToInstance(SomeClass, { aNumber: 1 });
const partialB = plainToInstance(SomeClass, { aString: "abc" });
console.log({ ...partialA, ...partialB });
// Expected: { aNumber: 1, aString: 'abc' }
// Actual:   { aNumber: undefined, aString: 'abc' }

Issue Number: N/A

What is the new behavior?

console.log({ ...partialA, ...partialB });
// Logs: { aNumber: 1, aString: 'abc' }

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Relates to swc-project/swc#3459

Reproduction repo available https://github.com/tuxmachine/swc-class-transformer

SWC adopts ESNext behaviour of explicitly setting fields as `undefined` by default. Disabling this behaviour aligns better with TS that targets ES2021
@kamilmysliwiec
Copy link
Member

LGTM ❤️

@kamilmysliwiec kamilmysliwiec merged commit be5d1d0 into nestjs:master Jul 11, 2023
@rickdgeerling rickdgeerling deleted the patch-1 branch July 11, 2023 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants