Skip to content

Commit

Permalink
fix dulicate case in merge
Browse files Browse the repository at this point in the history
  • Loading branch information
charlescatta committed Apr 3, 2024
1 parent 04ab765 commit 1ce249c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
50 changes: 24 additions & 26 deletions deno/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@ const templateLiteral = z.templateLiteral(); // infers to ``.
- To add string literal types to an existing template literal:

```ts
templateLiteral.literal('Hello'); // infers to `Hello`.
templateLiteral.literal("Hello"); // infers to `Hello`.
templateLiteral.literal(3.14); // infers to `3.14`.
```

Expand All @@ -2048,17 +2048,17 @@ const templateLiteral = z.templateLiteral(); // infers to ``.
templateLiteral.interpolated(z.string()); // infers to `${string}`.
templateLiteral.interpolated(z.number()); // infers to `${number}`.
templateLiteral.interpolated(z.boolean()); // infers to `true` | `false`.
templateLiteral.interpolated(z.literal('foo')); // infers to `foo`.
templateLiteral.interpolated(z.literal("foo")); // infers to `foo`.
templateLiteral.interpolated(z.null()); // infers to `null`.
templateLiteral.interpolated(z.undefined()); // infers to `undefined`.
templateLiteral.interpolated(z.bigint()); // infers to `${bigint}`.
templateLiteral.interpolated(z.any()); // infers to `${any}`.
```

Any Zod type (or union) with an underlying type of string, number, boolean, null,
undefined or bigint can be used as an interpolated position (template literals
included!). You can use additional built-in runtime validations (refinements
excluded) in each of these types and the template literal builder will do its
Any Zod type (or union) with an underlying type of string, number, boolean, null,
undefined or bigint can be used as an interpolated position (template literals
included!). You can use additional built-in runtime validations (refinements
excluded) in each of these types and the template literal builder will do its
best (within the limitations of regular expressions) to support them when parsing.

### Examples
Expand All @@ -2076,22 +2076,22 @@ const url = z

url.parse("https://google.com"); // passes
url.parse("https://google.net"); // passes
url.parse('http://google.com'); // throws
url.parse('https://.com'); // throws
url.parse('https://google'); // throws
url.parse('https://google.'); // throws
url.parse('https://google.gov'); // throws
url.parse("http://google.com"); // throws
url.parse("https://.com"); // throws
url.parse("https://google"); // throws
url.parse("https://google."); // throws
url.parse("https://google.gov"); // throws
```

Measurement:

```ts
const measurement = z.coerce
.templateLiteral()
.interpolated(z.number().finite())
.interpolated(
z.enum(["px", "em", "rem", "vh", "vw", "vmin", "vmax"]).optional()
);
.templateLiteral()
.interpolated(z.number().finite())
.interpolated(
z.enum(["px", "em", "rem", "vh", "vw", "vmin", "vmax"]).optional()
);
// infers to `${number}` | `${number}px` | `${number}em` | `${number}rem` | `${number}vh` | `${number}vw` | `${number}vmin` | `${number}vmax
```

Expand All @@ -2112,9 +2112,7 @@ const connectionString = z
)
.interpolated(z.string().regex(/\w+/).describe("host"))
.literal(":")
.interpolated(
z.number().finite().int().positive().describe("port")
)
.interpolated(z.number().finite().int().positive().describe("port"))
.interpolated(
z
.templateLiteral()
Expand All @@ -2132,13 +2130,13 @@ const connectionString = z
)
.optional()
);
// infers to:
// | `mongodb://${string}:${number}`
// | `mongodb://${string}:${number}/${string}`
// | `mongodb://${string}:${number}/${string}?${string}`
// | `mongodb://${string}:${string}@${string}:${number}`
// | `mongodb://${string}:${string}@${string}:${number}/${string}`
// | `mongodb://${string}:${string}@${string}:${number}/${string}?${string}`
// infers to:
// | `mongodb://${string}:${number}`
// | `mongodb://${string}:${number}/${string}`
// | `mongodb://${string}:${number}/${string}?${string}`
// | `mongodb://${string}:${string}@${string}:${number}`
// | `mongodb://${string}:${string}@${string}:${number}/${string}`
// | `mongodb://${string}:${string}@${string}:${number}/${string}?${string}`
```

## Preprocess
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/firstparty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ test("first party switch", () => {
break;
case z.ZodFirstPartyTypeKind.ZodTemplateLiteral:
break;
case z.ZodFirstPartyTypeKind.ZodReadonly:
break;
default:
util.assertNever(def);
}
Expand Down

0 comments on commit 1ce249c

Please sign in to comment.