Skip to content

Commit

Permalink
docs: infer Literal from the schema in JSON type example (colinhack…
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbruijn authored and MrAwesome committed May 20, 2022
1 parent a764e21 commit c9c43c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -1185,9 +1185,9 @@ const Category: z.ZodType<Category> = BaseCategory.merge(
If you want to validate any JSON value, you can use the snippet below.

```ts
type Literal = boolean | null | number | string;
type Json = Literal | { [key: string]: Json } | Json[];
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
type Literal = z.infer<typeof literalSchema>;
type Json = Literal | { [key: string]: Json } | Json[];
const jsonSchema: z.ZodType<Json> = z.lazy(() =>
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
);
Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Expand Up @@ -1012,9 +1012,9 @@ const Category: z.ZodSchema<Category> = BaseCategory.merge(
如果你想验证任何 JSON 值,你可以使用下面的片段。

```ts
type Literal = boolean | null | number | string;
type Json = Literal | { [key: string]: Json } | Json[];
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
type Literal = z.infer<typeof literalSchema>;
type Json = Literal | { [key: string]: Json } | Json[];
const jsonSchema: z.ZodSchema<Json> = z.lazy(() =>
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
);
Expand Down

0 comments on commit c9c43c4

Please sign in to comment.