Repository: fabien0102/ts-to-zod
Pull request #25 (2021-05-26 10:24:21)

feat: Add `never` support
# Why

The `never` keyword was forgot and could be translated by `z.never()`

## Related issue

#24


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

[![Impacted file tree graph](https://codecov.io/gh/fabien0102/ts-to-zod/pull/25/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/25?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      #25      +/-   ##
==========================================
- Coverage   98.49%   98.30%   -0.19%     
==========================================
  Files           8        9       +1     
  Lines         332      355      +23     
  Branches      102      100       -2     
==========================================
+ Hits          327      349      +22     
  Misses          5        5              
- Partials        0        1       +1     
```


| [Impacted Files](https://codecov.io/gh/fabien0102/ts-to-zod/pull/25?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/25/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/25/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.22% <100.00%> (+0.01%)` | :arrow_up: |
| [src/core/validateGeneratedTypes.ts](https://codecov.io/gh/fabien0102/ts-to-zod/pull/25/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/25?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/25?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD). Last update [9a3a69b...53d3341](https://codecov.io/gh/fabien0102/ts-to-zod/pull/25?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/example/heros.ts b/example/heros.ts
index eff1de3..68639a8 100644
--- a/example/heros.ts
+++ b/example/heros.ts
@@ -15,6 +15,7 @@ export interface Villain {
   name: string;
   powers: string[];
   friends: Villain[];
+  canBeTrusted: never;
 }
 
 export interface EvilPlan {
diff --git a/example/heros.zod.ts b/example/heros.zod.ts
index 9fcfbbe..bb46b69 100644
--- a/example/heros.zod.ts
+++ b/example/heros.zod.ts
@@ -24,6 +24,7 @@ export const villainSchema: z.ZodSchema<Villain> = z.lazy(() =>
     name: z.string(),
     powers: z.array(z.string()),
     friends: z.array(villainSchema),
+    canBeTrusted: z.never(),
   })
 );
 
diff --git a/src/core/generateZodSchema.ts b/src/core/generateZodSchema.ts
index bb7dd5c..a7542e1 100644
--- a/src/core/generateZodSchema.ts
+++ b/src/core/generateZodSchema.ts
@@ -574,6 +574,8 @@ function buildZodPrimitive({
       return buildZodSchema(z, "bigint", [], zodProperties);
     case ts.SyntaxKind.VoidKeyword:
       return buildZodSchema(z, "void", [], zodProperties);
+    case ts.SyntaxKind.NeverKeyword:
+      return buildZodSchema(z, "never", [], zodProperties);
   }
 
   console.warn(


Test patch:
diff --git a/src/core/generateZodSchema.test.ts b/src/core/generateZodSchema.test.ts
index 08a02d7..d447af1 100644
--- a/src/core/generateZodSchema.test.ts
+++ b/src/core/generateZodSchema.test.ts
@@ -88,6 +88,13 @@ describe("generateZodSchema", () => {
     );
   });
 
+  it("should generate a never", () => {
+    const source = `export type CanBeatZod = never;`;
+    expect(generate(source)).toMatchInlineSnapshot(
+      `"export const canBeatZodSchema = z.never();"`
+    );
+  });
+
   it("should generate an array schema (T[] notation)", () => {
     const source = `export type Villains = string[];`;
     expect(generate(source)).toMatchInlineSnapshot(