Skip to content

Commit 90feca3

Browse files
fix: do not call function properties during plain to class transformation
references typestack#596
1 parent c185beb commit 90feca3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/TransformOperationExecutor.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,22 @@ export class TransformOperationExecutor {
184184

185185
// get a subvalue
186186
let subValue: any = undefined;
187-
if (value instanceof Map) {
188-
subValue = value.get(valueKey);
189-
} else if (value[valueKey] instanceof Function) {
190-
subValue = value[valueKey]();
191-
} else {
187+
if (this.transformationType === TransformationType.PLAIN_TO_CLASS) {
188+
/**
189+
* This section is added for the following report:
190+
* https://github.com/typestack/class-transformer/issues/596
191+
*
192+
* We should not call functions or constructors when transforming to class.
193+
*/
192194
subValue = value[valueKey];
195+
} else {
196+
if (value instanceof Map) {
197+
subValue = value.get(valueKey);
198+
} else if (value[valueKey] instanceof Function) {
199+
subValue = value[valueKey]();
200+
} else {
201+
subValue = value[valueKey];
202+
}
193203
}
194204

195205
// determine a type
@@ -254,6 +264,7 @@ export class TransformOperationExecutor {
254264
propertyName
255265
);
256266

267+
console.log({ reflectedType });
257268
if (reflectedType) {
258269
type = reflectedType;
259270
}

0 commit comments

Comments
 (0)