Repository: fabien0102/ts-to-zod
Pull request #83 (2022-06-02 04:59:07)

feat: Map unknown type to `z.unknown()`

codecov-commenter: # [Codecov](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) Report
> Merging [#83](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) (c093220) 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 `1.35%`.
> The diff coverage is `96.23%`.

```diff
@@            Coverage Diff             @@
##             main      #83      +/-   ##
==========================================
- Coverage   98.49%   97.14%   -1.36%     
==========================================
  Files           8       12       +4     
  Lines         332      455     +123     
  Branches      102      151      +49     
==========================================
+ Hits          327      442     +115     
- Misses          5       11       +6     
- Partials        0        2       +2     
```


| [Impacted Files](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) | Coverage Δ | |
|---|---|---|
| [src/core/generateZodSchema.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL2NvcmUvZ2VuZXJhdGVab2RTY2hlbWEudHM=) | `95.02% <92.10%> (-2.18%)` | :arrow_down: |
| [src/utils/resolveModules.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL3V0aWxzL3Jlc29sdmVNb2R1bGVzLnRz) | `97.67% <97.67%> (ø)` | |
| [src/core/generate.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL2NvcmUvZ2VuZXJhdGUudHM=) | `100.00% <100.00%> (ø)` | |
| [src/core/jsDocTags.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/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.57% <100.00%> (-1.43%)` | :arrow_down: |
| [src/core/validateGeneratedTypes.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/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.05% <100.00%> (-0.31%)` | :arrow_down: |
| [src/utils/getSimplifiedJsDocTags.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL3V0aWxzL2dldFNpbXBsaWZpZWRKc0RvY1RhZ3MudHM=) | `100.00% <100.00%> (ø)` | |
| [src/utils/isNotNull.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL3V0aWxzL2lzTm90TnVsbC50cw==) | `100.00% <100.00%> (ø)` | |
| [src/utils/resolveDefaultProperties.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD#diff-c3JjL3V0aWxzL3Jlc29sdmVEZWZhdWx0UHJvcGVydGllcy50cw==) | `100.00% <100.00%> (ø)` | |
| ... and [6 more](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83?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/83?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD). Last update [fc7153f...c093220](https://codecov.io/gh/fabien0102/ts-to-zod/pull/83?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/README.md b/README.md
index 3cf65e1..68fbc85 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,7 @@ To make sure the generated zod schemas are 100% compatible with your original ty
 Notes:
 
 - Only exported types/interface are tested (so you can have some private types/interface and just exports the composed type)
-- Even if this is not recommanded, you can skip this validation step with `--skipValidation`. (At your own risk!)
+- Even if this is not recommended, you can skip this validation step with `--skipValidation`. (At your own risk!)
 
 ## Validators
 
diff --git a/src/core/generateZodSchema.ts b/src/core/generateZodSchema.ts
index 90a3368..3174098 100644
--- a/src/core/generateZodSchema.ts
+++ b/src/core/generateZodSchema.ts
@@ -702,6 +702,8 @@ function buildZodPrimitive({
       return buildZodSchema(z, "void", [], zodProperties);
     case ts.SyntaxKind.NeverKeyword:
       return buildZodSchema(z, "never", [], zodProperties);
+    case ts.SyntaxKind.UnknownKeyword:
+      return buildZodSchema(z, "unknown", [], zodProperties);
   }
 
   console.warn(


Test patch:
diff --git a/src/core/generateZodSchema.test.ts b/src/core/generateZodSchema.test.ts
index b2e71c4..6e1936a 100644
--- a/src/core/generateZodSchema.test.ts
+++ b/src/core/generateZodSchema.test.ts
@@ -125,6 +125,13 @@ describe("generateZodSchema", () => {
     );
   });
 
+  it("should map unknown type correctly", () => {
+    const source = `export type T = unknown;`;
+    expect(generate(source)).toMatchInlineSnapshot(
+      `"export const tSchema = z.unknown();"`
+    );
+  });
+
   it("should generate an array schema (T[] notation)", () => {
     const source = `export type Villains = string[];`;
     expect(generate(source)).toMatchInlineSnapshot(