Skip to content

Commit

Permalink
BRAND Record to Non Partial (#2097)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Feb 26, 2023
1 parent a7c2969 commit 8f3d028
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
20 changes: 13 additions & 7 deletions deno/lib/README.md
Expand Up @@ -1409,7 +1409,7 @@ type NumberSet = z.infer<typeof numberSet>;
// type NumberSet = Set<number>
```

Set schemas can be further contrainted with the following utility methods.
Set schemas can be further constrained with the following utility methods.

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

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).

```ts
z.custom<...>((val) => ..., "custom error message");
```

## Schema methods

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

```ts
const data = z
const result = z
.object({
name: z.string(),
})
.safeParse({ name: 12 });

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

```ts
const data = z
const result = z
.object({
name: z.string(),
})
.safeParse({ name: 12 });

if (!data.success) {
const formatted = data.error.format();
if (!result.success) {
const formatted = result.error.format();
/* {
name: { _errors: [ 'Expected string, received number' ] }
} */
Expand Down
2 changes: 2 additions & 0 deletions deno/lib/types.ts
Expand Up @@ -3066,6 +3066,8 @@ export type RecordType<K extends string | number | symbol, V> = [
? Record<K, V>
: [symbol] extends [K]
? Record<K, V>
: K extends BRAND<string | number | symbol>
? Record<K, V>
: Partial<Record<K, V>>;
export class ZodRecord<
Key extends KeySchema = ZodString,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Expand Up @@ -3066,6 +3066,8 @@ export type RecordType<K extends string | number | symbol, V> = [
? Record<K, V>
: [symbol] extends [K]
? Record<K, V>
: K extends BRAND<string | number | symbol>
? Record<K, V>
: Partial<Record<K, V>>;
export class ZodRecord<
Key extends KeySchema = ZodString,
Expand Down

0 comments on commit 8f3d028

Please sign in to comment.