Skip to content

Commit 090d050

Browse files
authored
feat: add support for object keyword (#293)
1 parent d2d353e commit 090d050

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/core/generateZodSchema.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,13 @@ describe("generateZodSchema", () => {
758758
);
759759
});
760760

761+
it("should generate an object schema", () => {
762+
const source = `export type Object = object;`;
763+
expect(generate(source)).toMatchInlineSnapshot(
764+
`"export const objectSchema = z.record(z.any());"`
765+
);
766+
});
767+
761768
it("should generate custom validators based on jsdoc tags", () => {
762769
const source = `export interface HeroContact {
763770
/**

src/core/generateZodSchema.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,13 @@ function buildZodPrimitiveInternal({
10131013
return buildZodSchema(z, "never", [], zodProperties);
10141014
case ts.SyntaxKind.UnknownKeyword:
10151015
return buildZodSchema(z, "unknown", [], zodProperties);
1016+
case ts.SyntaxKind.ObjectKeyword:
1017+
return buildZodSchema(
1018+
z,
1019+
"record",
1020+
[buildZodSchema(z, "any")],
1021+
zodProperties
1022+
);
10161023
}
10171024

10181025
if (ts.isTemplateLiteralTypeNode(typeNode)) {

0 commit comments

Comments
 (0)