Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BRAND Record to Non Partial #2097

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions deno/lib/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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