From 555be4fef3234b2df275ecf797c1b6b78ba40df5 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Mon, 22 Jul 2024 02:33:46 +0900 Subject: [PATCH 1/3] Fix #1166: nonsensible intersection type case --- benchmark/package.json | 2 +- debug/features/intersection.ts | 15 ++++++++++++ debug/package.json | 2 +- errors/package.json | 2 +- package.json | 2 +- packages/typescript-json/package.json | 4 ++-- .../metadata/iterate_metadata_intersection.ts | 24 +++++++++++-------- test-esm/package.json | 2 +- test/package.json | 2 +- 9 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 debug/features/intersection.ts diff --git a/benchmark/package.json b/benchmark/package.json index 103e84da5f..f4cfa4f134 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -72,6 +72,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^3.0.0", "uuid": "^9.0.1", - "typia": "../typia-6.5.3.tgz" + "typia": "../typia-6.5.4-dev.20240721.tgz" } } \ No newline at end of file diff --git a/debug/features/intersection.ts b/debug/features/intersection.ts new file mode 100644 index 0000000000..4fe57c5f00 --- /dev/null +++ b/debug/features/intersection.ts @@ -0,0 +1,15 @@ +import typia from "typia"; + +console.log( + typia.createIs<2 & number>().toString(), + typia.createIs<3 & 4 & number>().toString(), + typia + .createIs< + [ + { + id: never; + }, + ] + >() + .toString(), +); diff --git a/debug/package.json b/debug/package.json index 5da4b7838b..c6ef3553d7 100644 --- a/debug/package.json +++ b/debug/package.json @@ -15,6 +15,6 @@ "typescript": "^5.4.2" }, "dependencies": { - "typia": "../typia-6.5.3-dev.20240720.tgz" + "typia": "../typia-6.5.4-dev.20240721.tgz" } } \ No newline at end of file diff --git a/errors/package.json b/errors/package.json index 4a9168bfe6..a338f7f5cb 100644 --- a/errors/package.json +++ b/errors/package.json @@ -32,6 +32,6 @@ "typescript": "^5.3.2" }, "dependencies": { - "typia": "../typia-6.5.3.tgz" + "typia": "../typia-6.5.4-dev.20240721.tgz" } } \ No newline at end of file diff --git a/package.json b/package.json index fc05b43c52..b83331bcb6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "6.5.3", + "version": "6.5.4-dev.20240721", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/typescript-json/package.json b/packages/typescript-json/package.json index 977d4c281a..0caaa2b08c 100644 --- a/packages/typescript-json/package.json +++ b/packages/typescript-json/package.json @@ -1,6 +1,6 @@ { "name": "typescript-json", - "version": "6.5.3", + "version": "6.5.4-dev.20240721", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -63,7 +63,7 @@ }, "homepage": "https://typia.io", "dependencies": { - "typia": "6.5.3" + "typia": "6.5.4-dev.20240721" }, "peerDependencies": { "typescript": ">=4.8.0 <5.6.0" diff --git a/src/factories/internal/metadata/iterate_metadata_intersection.ts b/src/factories/internal/metadata/iterate_metadata_intersection.ts index 20e0159ff5..19df54b1f5 100644 --- a/src/factories/internal/metadata/iterate_metadata_intersection.ts +++ b/src/factories/internal/metadata/iterate_metadata_intersection.ts @@ -27,7 +27,8 @@ export const iterate_metadata_intersection = explore: MetadataFactory.IExplore, ): boolean => { if (!type.isIntersection()) return false; - else if ( + if ( + // ONLY OBJECT TYPED INTERSECTION type.types.every( (child) => (child.getFlags() & ts.TypeFlags.Object) !== 0 && @@ -68,9 +69,18 @@ export const iterate_metadata_intersection = ); return true; } else if (children.every((c) => c.objects.length === c.size())) + // ONLY OBJECT TYPED INTERSECTION (DETAILED) return false; // VALIDATE EACH TYPES + const nonsensible = () => { + errors.push({ + name: children.map((c) => c.getName()).join(" & "), + explore: { ...explore }, + messages: ["nonsensible intersection"], + }); + return true; + }; const individuals: (readonly [Metadata, number])[] = children .map((child, i) => [child, i] as const) .filter( @@ -82,7 +92,7 @@ export const iterate_metadata_intersection = c.arrays.length === 1)) || c.templates.length === 1, ); - if (individuals.length !== 1) return false; + if (individuals.length !== 1) return nonsensible(); const objects: Metadata[] = children.filter( (c) => @@ -109,14 +119,8 @@ export const iterate_metadata_intersection = if ( atomics.size + constants.length + arrays.size + templates.length > 1 || individuals.length + objects.length !== children.length - ) { - errors.push({ - name: children.map((c) => c.getName()).join(" & "), - explore: { ...explore }, - messages: ["nonsensible intersection"], - }); - return true; - } + ) + return nonsensible(); // RE-GENERATE TYPE const target: "boolean" | "bigint" | "number" | "string" | "array" = diff --git a/test-esm/package.json b/test-esm/package.json index 6b3ec99024..b6686794ce 100644 --- a/test-esm/package.json +++ b/test-esm/package.json @@ -36,6 +36,6 @@ "typescript": "^5.4.5" }, "dependencies": { - "typia": "../typia-6.5.3.tgz" + "typia": "../typia-6.5.4-dev.20240721.tgz" } } \ No newline at end of file diff --git a/test/package.json b/test/package.json index c836bb9ab6..d340da6c80 100644 --- a/test/package.json +++ b/test/package.json @@ -51,6 +51,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^3.0.0", "uuid": "^9.0.1", - "typia": "../typia-6.5.3.tgz" + "typia": "../typia-6.5.4-dev.20240721.tgz" } } \ No newline at end of file From 741d7c62760b20bf3dd8c838488acc759a855a9c Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Mon, 22 Jul 2024 02:42:36 +0900 Subject: [PATCH 2/3] Also add bug test case --- debug/features/intersection.ts | 17 ++++------------- .../error_nonsensible_intersection.ts | 6 ++++++ 2 files changed, 10 insertions(+), 13 deletions(-) create mode 100644 errors/src/nonsensible/error_nonsensible_intersection.ts diff --git a/debug/features/intersection.ts b/debug/features/intersection.ts index 4fe57c5f00..067c27f4fd 100644 --- a/debug/features/intersection.ts +++ b/debug/features/intersection.ts @@ -1,15 +1,6 @@ import typia from "typia"; -console.log( - typia.createIs<2 & number>().toString(), - typia.createIs<3 & 4 & number>().toString(), - typia - .createIs< - [ - { - id: never; - }, - ] - >() - .toString(), -); +type Art = `${string}art${string}`; +type Bar = `${string}bar${string}`; + +console.log(typia.createIs().toString()); diff --git a/errors/src/nonsensible/error_nonsensible_intersection.ts b/errors/src/nonsensible/error_nonsensible_intersection.ts new file mode 100644 index 0000000000..a5ed193825 --- /dev/null +++ b/errors/src/nonsensible/error_nonsensible_intersection.ts @@ -0,0 +1,6 @@ +import typia from "typia"; + +type Art = `${string}art${string}`; +type Bar = `${string}bar${string}`; + +typia.createIs(); From 14e2be3fa958fcad2f0a341d86c506d90d4a2c79 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Mon, 22 Jul 2024 03:18:46 +0900 Subject: [PATCH 3/3] Publish v6.5.4 update --- benchmark/package.json | 2 +- errors/package.json | 2 +- package.json | 2 +- packages/typescript-json/package.json | 4 ++-- test-esm/package.json | 2 +- test/package.json | 2 +- website/package.json | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/benchmark/package.json b/benchmark/package.json index f4cfa4f134..55e73ca667 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -72,6 +72,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^3.0.0", "uuid": "^9.0.1", - "typia": "../typia-6.5.4-dev.20240721.tgz" + "typia": "../typia-6.5.4.tgz" } } \ No newline at end of file diff --git a/errors/package.json b/errors/package.json index a338f7f5cb..282a1efe9b 100644 --- a/errors/package.json +++ b/errors/package.json @@ -32,6 +32,6 @@ "typescript": "^5.3.2" }, "dependencies": { - "typia": "../typia-6.5.4-dev.20240721.tgz" + "typia": "../typia-6.5.4.tgz" } } \ No newline at end of file diff --git a/package.json b/package.json index b83331bcb6..cca9a31b35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "6.5.4-dev.20240721", + "version": "6.5.4", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/typescript-json/package.json b/packages/typescript-json/package.json index 0caaa2b08c..9ff123bbfc 100644 --- a/packages/typescript-json/package.json +++ b/packages/typescript-json/package.json @@ -1,6 +1,6 @@ { "name": "typescript-json", - "version": "6.5.4-dev.20240721", + "version": "6.5.4", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -63,7 +63,7 @@ }, "homepage": "https://typia.io", "dependencies": { - "typia": "6.5.4-dev.20240721" + "typia": "6.5.4" }, "peerDependencies": { "typescript": ">=4.8.0 <5.6.0" diff --git a/test-esm/package.json b/test-esm/package.json index b6686794ce..e68a8a9a81 100644 --- a/test-esm/package.json +++ b/test-esm/package.json @@ -36,6 +36,6 @@ "typescript": "^5.4.5" }, "dependencies": { - "typia": "../typia-6.5.4-dev.20240721.tgz" + "typia": "../typia-6.5.4.tgz" } } \ No newline at end of file diff --git a/test/package.json b/test/package.json index d340da6c80..1729ba3e75 100644 --- a/test/package.json +++ b/test/package.json @@ -51,6 +51,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^3.0.0", "uuid": "^9.0.1", - "typia": "../typia-6.5.4-dev.20240721.tgz" + "typia": "../typia-6.5.4.tgz" } } \ No newline at end of file diff --git a/website/package.json b/website/package.json index 71e9e6cfe5..d696ed83e3 100644 --- a/website/package.json +++ b/website/package.json @@ -37,7 +37,7 @@ "tgrid": "^1.0.2", "tstl": "^3.0.0", "typescript": "^5.5.3", - "typia": "^6.5.3" + "typia": "^6.5.4" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0",