From d8b9dd32d49d6a0fefcf8f58ab221b8a75ff9b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Thu, 27 Jul 2023 13:42:08 +0200 Subject: [PATCH] fix: apply optional decorator to metadata factory props --- lib/type-helpers/partial-type.helper.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/type-helpers/partial-type.helper.ts b/lib/type-helpers/partial-type.helper.ts index 03d3ddde1..b13571a6e 100644 --- a/lib/type-helpers/partial-type.helper.ts +++ b/lib/type-helpers/partial-type.helper.ts @@ -34,6 +34,15 @@ export function PartialType(classRef: Type): Type> { mapValues(metadata, (item) => ({ ...item, required: false })) ); + if (PartialTypeClass[METADATA_FACTORY_NAME]) { + const pluginFields = Object.keys( + PartialTypeClass[METADATA_FACTORY_NAME]() + ); + pluginFields.forEach((key) => + applyIsOptionalDecorator(PartialTypeClass, key) + ); + } + fields.forEach((key) => { const metadata = Reflect.getMetadata( @@ -59,12 +68,5 @@ export function PartialType(classRef: Type): Type> { applyFields(fields); }); - if (PartialTypeClass[METADATA_FACTORY_NAME]) { - const pluginFields = Object.keys(PartialTypeClass[METADATA_FACTORY_NAME]()); - pluginFields.forEach((key) => - applyIsOptionalDecorator(PartialTypeClass, key) - ); - } - return PartialTypeClass as Type>; }