How to keep unused class properties? #2438
Answered
by
michael-land
michael-land
asked this question in
Q&A
-
{
"jsc": {
"keepClassNames": true,
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true,
"optimizer": null
},
"target": "es2020"
},
"module": {
"type": "commonjs"
}
}
Input import { plainToClass } from 'class-transformer';
import { IsString } from 'class-validator';
export class MyPayload {
@IsString()
email: string;
}
const d = plainToClass(MyPayload, { email: '123' });
// swc remove email from class after compile, this will output `MyPayload {}` instead of `MyPayload { email: "123"}`
console.log(d); Output var _class, _descriptor, _dec, _dec1;
let MyPayload1 = ((_class = class MyPayload {
constructor(){
_initializerDefineProperty(this, "email", _descriptor, this);
}
}) || _class, _dec = (0, _classValidator).IsString(), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String), _descriptor = _applyDecoratedDescriptor(_class.prototype, "email", [
_dec,
_dec1
], {
configurable: true,
enumerable: true,
writable: true,
initializer: void 0
}), _class);
exports.MyPayload = MyPayload1;
const d = (0, _classTransformer).plainToClass(MyPayload1, {
email: '123'
}, {
ignoreDecorators: true
});
console.log(d); is there anyway to not strip unused properties? swc remove email field from class after compile, this will output |
Beta Was this translation helpful? Give feedback.
Answered by
michael-land
Oct 15, 2021
Replies: 1 comment
-
NVM #2117 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
michael-land
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NVM #2117