Skip to content

Commit

Permalink
feat: Add never support (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed May 26, 2021
1 parent 9a3a69b commit 3267f67
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/heros.ts
Expand Up @@ -15,6 +15,7 @@ export interface Villain {
name: string;
powers: string[];
friends: Villain[];
canBeTrusted: never;
}

export interface EvilPlan {
Expand Down
1 change: 1 addition & 0 deletions example/heros.zod.ts
Expand Up @@ -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(),
})
);

Expand Down
7 changes: 7 additions & 0 deletions src/core/generateZodSchema.test.ts
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/core/generateZodSchema.ts
Expand Up @@ -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(
Expand Down

0 comments on commit 3267f67

Please sign in to comment.