Skip to content

Commit

Permalink
Fix #1166: nonsensible intersection type case
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Jul 21, 2024
1 parent b8f796e commit 555be4f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
15 changes: 15 additions & 0 deletions debug/features/intersection.ts
Original file line number Diff line number Diff line change
@@ -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(),
);
2 changes: 1 addition & 1 deletion debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "../typia-6.5.3.tgz"
"typia": "../typia-6.5.4-dev.20240721.tgz"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down
24 changes: 14 additions & 10 deletions src/factories/internal/metadata/iterate_metadata_intersection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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(
Expand All @@ -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) =>
Expand All @@ -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" =
Expand Down
2 changes: 1 addition & 1 deletion test-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"typescript": "^5.4.5"
},
"dependencies": {
"typia": "../typia-6.5.3.tgz"
"typia": "../typia-6.5.4-dev.20240721.tgz"
}
}
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 555be4f

Please sign in to comment.