Repository: fabien0102/ts-to-zod
Pull request #32 (2021-05-31 07:43:25)

feat: Add `Date` support
# Why

Generate `z.date()` for `Date`

## Related issue

#31 

codecov-commenter: # [Codecov](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) Report
> Merging [#32](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) (84b8768) into [main](https://codecov.io/gh/fabien0102/ts-to-zod/commit/e5e49615d832129cae8a23cbf5fa0b35024e15e2?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) (e5e4961) will **decrease** coverage by `0.45%`.
> The diff coverage is `96.29%`.

[![Impacted file tree graph](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32/graphs/tree.svg?width=650&height=150&src=pr&token=W5M8UIJ59C&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD)](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD)

```diff
@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
- Coverage   98.49%   98.03%   -0.46%     
==========================================
  Files           8        9       +1     
  Lines         332      357      +25     
  Branches      102      101       -1     
==========================================
+ Hits          327      350      +23     
- Misses          5        6       +1     
- Partials        0        1       +1     
```


| [Impacted Files](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) | Coverage Δ | |
|---|---|---|
| [src/utils/resolveDefaultProperties.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL3V0aWxzL3Jlc29sdmVEZWZhdWx0UHJvcGVydGllcy50cw==) | `95.23% <95.23%> (ø)` | |
| [src/core/generateZodSchema.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL2NvcmUvZ2VuZXJhdGVab2RTY2hlbWEudHM=) | `97.26% <100.00%> (+0.05%)` | :arrow_up: |
| [src/core/jsDocTags.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL2NvcmUvanNEb2NUYWdzLnRz) | `98.46% <100.00%> (-1.54%)` | :arrow_down: |
| [src/core/validateGeneratedTypes.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL2NvcmUvdmFsaWRhdGVHZW5lcmF0ZWRUeXBlcy50cw==) | `97.43% <100.00%> (+0.06%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD). Last update [ce06ede...84b8768](https://codecov.io/gh/fabien0102/ts-to-zod/pull/32?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD).


Patch:
diff --git a/src/core/generateZodSchema.ts b/src/core/generateZodSchema.ts
index a7542e1..b0311f3 100644
--- a/src/core/generateZodSchema.ts
+++ b/src/core/generateZodSchema.ts
@@ -292,6 +292,11 @@ function buildZodPrimitive({
       );
     }
 
+    // Deal with `Date`
+    if (identifierName === "Date") {
+      return buildZodSchema(z, "date", [], zodProperties);
+    }
+
     // Deal with `Promise<>` syntax
     if (identifierName === "Promise" && typeNode.typeArguments) {
       return buildZodSchema(


Test patch:
diff --git a/src/core/generateZodSchema.test.ts b/src/core/generateZodSchema.test.ts
index d447af1..9ea8d28 100644
--- a/src/core/generateZodSchema.test.ts
+++ b/src/core/generateZodSchema.test.ts
@@ -60,6 +60,13 @@ describe("generateZodSchema", () => {
     );
   });
 
+  it("should generate a date schema", () => {
+    const source = `export type lastIncidentInMetropolis = Date;`;
+    expect(generate(source)).toMatchInlineSnapshot(
+      `"export const lastIncidentInMetropolisSchema = z.date();"`
+    );
+  });
+
   it("should generate a literal schema (string)", () => {
     const source = `export type Kryptonite = "kryptonite";`;
     expect(generate(source)).toMatchInlineSnapshot(