Skip to content

Commit

Permalink
Fix #734 - union type predicator broken when native type like Date
Browse files Browse the repository at this point in the history
…being used

Fixed that bug, and new version is `4.1.14`.

The bug had been occured by ommission of native types in intersection algorithm of `Metadata`.
  • Loading branch information
samchon committed Aug 2, 2023
1 parent 68e428d commit 1ac8563
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 25 deletions.
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": "4.1.13",
"version": "4.1.14",
"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": "4.1.13",
"version": "4.1.14",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -68,7 +68,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "4.1.13"
"typia": "4.1.14"
},
"peerDependencies": {
"typescript": ">= 4.7.4"
Expand Down
5 changes: 5 additions & 0 deletions src/metadata/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ export namespace Metadata {
if (x.objects.length && y.objects.length) return true;
if (x.aliases.length && y.aliases.length) return true;

// NATIVES
if (x.natives.length && y.natives.length)
if (x.natives.some((xn) => y.natives.some((yn) => xn === yn)))
return true;

//----
// VALUES
//----
Expand Down
28 changes: 28 additions & 0 deletions test/features/issues/test_issue_native_union_property.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import typia from "typia";

type A = {
createdAt: Date;
value: number;
};
type B = {
createdAt: Date;
value: string;
};
type AB = A | B;

export const test_issue_native_union_property = () => {
const matched: boolean[] = [
{
createdAt: new Date(),
value: 10,
},
{
createdAt: new Date(),
value: "test",
},
].map((input) => typia.is<AB>(input));
if (matched.some((v) => v === false))
throw new Error(
"Bug on typia.is: failed to understand the native union property.",
);
};
27 changes: 27 additions & 0 deletions test/generated/output/issues/test_issue_native_union_property.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import typia from "typia";

type A = {
createdAt: Date;
value: number;
};
type B = {
createdAt: Date;
value: string;
};
type AB = A | B;
export const test_issue_native_union_property = () => {
const matched: boolean[] = [
{
createdAt: new Date(),
value: 10,
},
{
createdAt: new Date(),
value: "test",
},
].map((input) => typia.is<AB>(input));
if (matched.some((v) => v === false))
throw new Error(
"Bug on typia.is: failed to understand the native union property.",
);
};
13 changes: 13 additions & 0 deletions test/issues/native-union-property.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import typia from "typia";

type A = {
createdAt: Date;
value: number;
};
type B = {
createdAt: Date;
value: string;
};
type AB = A | B;

console.log(typia.createIs<AB>().toString());
8 changes: 4 additions & 4 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "5.1.6",
"typia": "^4.1.12"
"typia": "^4.1.14"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
Expand Down
34 changes: 17 additions & 17 deletions website/public/sitemap-0.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://typia.io/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/parse/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/schema/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/stringify/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/miscellaneous/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/pure/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/random/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/setup/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/nestjs/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/prisma/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/trpc/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/assert/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/comment-tags/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/is/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/validate/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/playground/</loc><lastmod>2023-07-31T08:47:27.998Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/parse/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/schema/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/stringify/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/miscellaneous/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/pure/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/random/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/setup/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/nestjs/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/prisma/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/trpc/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/assert/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/comment-tags/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/is/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/validate/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/playground/</loc><lastmod>2023-08-02T09:01:58.728Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
</urlset>

0 comments on commit 1ac8563

Please sign in to comment.