Skip to content

Commit

Permalink
feat: Add support for unknown type (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorefnon committed Jun 2, 2022
1 parent 01b9e62 commit f3bd8e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/generateZodSchema.test.ts
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/core/generateZodSchema.ts
Expand Up @@ -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(
Expand Down

0 comments on commit f3bd8e6

Please sign in to comment.