From faa923048820e4b515c5268a208a47b1d15a9f7c Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Thu, 28 Nov 2024 00:51:01 +0900 Subject: [PATCH] More safe escaping on intersection type diagnoser --- package.json | 2 +- .../metadata/iterate_metadata_intersection.ts | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 8ef6ae3d8e..8a1e9c3f9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "7.0.0-dev.20241127-3", + "version": "7.0.0-dev.20241127-4", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/src/factories/internal/metadata/iterate_metadata_intersection.ts b/src/factories/internal/metadata/iterate_metadata_intersection.ts index 177f9a3a6f..c8885ed579 100644 --- a/src/factories/internal/metadata/iterate_metadata_intersection.ts +++ b/src/factories/internal/metadata/iterate_metadata_intersection.ts @@ -37,11 +37,18 @@ export const iterate_metadata_intersection = ( intersected: false, }), ); + + // ERROR OR ANY TYPE CASE + const escape = () => { + Object.assign(props.collection, commit); + return false; + }; if (fakeErrors.length) { props.errors.push(...fakeErrors); return true; - } else if (children.length === 0) return false; - else if (children.some((m) => m.size() === 0)) return false; + } else if (children.length === 0) return escape(); + else if (children.some((m) => m.any === true || m.size() === 0)) + return escape(); // PREPARE MEATDATAS AND TAGS const indexes: number[] = []; @@ -78,15 +85,14 @@ export const iterate_metadata_intersection = ( messages: ["type tag cannot be standalone"], }); return true; - } else return false; + } else return escape(); // ONLY OBJECTS CASE else if ( metadatas.every((m) => m.objects.length === 1) && tagObjects.length === 0 - ) { - Object.assign(props.collection, commit); - return false; - } else if (metadatas.length !== 1) { + ) + return escape(); + else if (metadatas.length !== 1) { const indexes: number[] = metadatas .map((m, i) => m.size() === 1 &&