Skip to content

Commit 8f3d028

Browse files
authored
BRAND Record to Non Partial (#2097)
1 parent a7c2969 commit 8f3d028

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Diff for: deno/lib/README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ type NumberSet = z.infer<typeof numberSet>;
14091409
// type NumberSet = Set<number>
14101410
```
14111411

1412-
Set schemas can be further contrainted with the following utility methods.
1412+
Set schemas can be further constrained with the following utility methods.
14131413

14141414
```ts
14151415
z.set(z.string()).nonempty(); // must contain at least one item
@@ -1714,6 +1714,12 @@ If you don't provide a validation function, Zod will allow any value. This can b
17141714
z.custom<{ arg: string }>(); // performs no validation
17151715
```
17161716

1717+
You can customize the error message and other options by passing a second argument. This parameter works the same way as the params parameter of [`.refine`](#refine).
1718+
1719+
```ts
1720+
z.custom<...>((val) => ..., "custom error message");
1721+
```
1722+
17171723
## Schema methods
17181724

17191725
All Zod schemas contain certain methods.
@@ -2349,14 +2355,14 @@ makeSchemaOptional(z.number());
23492355
Zod provides a subclass of Error called `ZodError`. ZodErrors contain an `issues` array containing detailed information about the validation problems.
23502356

23512357
```ts
2352-
const data = z
2358+
const result = z
23532359
.object({
23542360
name: z.string(),
23552361
})
23562362
.safeParse({ name: 12 });
23572363

2358-
if (!data.success) {
2359-
data.error.issues;
2364+
if (!result.success) {
2365+
result.error.issues;
23602366
/* [
23612367
{
23622368
"code": "invalid_type",
@@ -2378,14 +2384,14 @@ Zod's error reporting emphasizes _completeness_ and _correctness_. If you are lo
23782384
You can use the `.format()` method to convert this error into a nested object.
23792385

23802386
```ts
2381-
const data = z
2387+
const result = z
23822388
.object({
23832389
name: z.string(),
23842390
})
23852391
.safeParse({ name: 12 });
23862392

2387-
if (!data.success) {
2388-
const formatted = data.error.format();
2393+
if (!result.success) {
2394+
const formatted = result.error.format();
23892395
/* {
23902396
name: { _errors: [ 'Expected string, received number' ] }
23912397
} */

Diff for: deno/lib/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3066,6 +3066,8 @@ export type RecordType<K extends string | number | symbol, V> = [
30663066
? Record<K, V>
30673067
: [symbol] extends [K]
30683068
? Record<K, V>
3069+
: K extends BRAND<string | number | symbol>
3070+
? Record<K, V>
30693071
: Partial<Record<K, V>>;
30703072
export class ZodRecord<
30713073
Key extends KeySchema = ZodString,

Diff for: src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3066,6 +3066,8 @@ export type RecordType<K extends string | number | symbol, V> = [
30663066
? Record<K, V>
30673067
: [symbol] extends [K]
30683068
? Record<K, V>
3069+
: K extends BRAND<string | number | symbol>
3070+
? Record<K, V>
30693071
: Partial<Record<K, V>>;
30703072
export class ZodRecord<
30713073
Key extends KeySchema = ZodString,

0 commit comments

Comments
 (0)