Skip to content

Commit

Permalink
Merge pull request #940 from EltonLobo07/doc/improve-issues-guide
Browse files Browse the repository at this point in the history
improve `Flatten errors` section's (issues guide) example
  • Loading branch information
fabian-hiller authored Dec 4, 2024
2 parents 16f004c + 050072a commit 65f0e59
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions website/src/routes/guides/(main-concepts)/issues/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: >-
contributors:
- fabian-hiller
- BastiDood
- EltonLobo07
---

import { Link } from '@builder.io/qwik-city';
Expand Down Expand Up @@ -119,13 +120,13 @@ If you are only interested in the error messages of each issue to show them to y
import * as v from 'valibot';

const ObjectSchema = v.object({
key: v.string('Value of "key" is missing.'),
nested: v.object({
key: v.string('Value of "nested.key" is missing.'),
foo: v.string('Value of "foo" is missing.'),
bar: v.object({
baz: v.string('Value of "bar.baz" is missing.'),
}),
});

const result = v.safeParse(ObjectSchema, { nested: {} });
const result = v.safeParse(ObjectSchema, { bar: {} });

if (result.issues) {
console.log(v.flatten<typeof ObjectSchema>(result.issues));
Expand All @@ -142,15 +143,16 @@ The `result` returned in the code sample above this text contains the following
input: undefined,
expected: 'string',
received: 'undefined',
message: 'Value of "key" is missing.',
message: 'Value of "foo" is missing.',
path: [
{
type: 'object',
origin: 'value',
input: {
nested: {},
bar: {},
},
key: 'key',
key: 'foo',
value: undefined,
},
],
},
Expand All @@ -160,22 +162,23 @@ The `result` returned in the code sample above this text contains the following
input: undefined,
expected: 'string',
received: 'undefined',
message: 'Value of "nested.key" is missing.',
message: 'Value of "bar.baz" is missing.',
path: [
{
type: 'object',
origin: 'value',
input: {
nested: {},
bar: {},
},
key: 'nested',
key: 'bar',
value: {},
},
{
type: 'object',
origin: 'value',
input: {},
key: 'key',
key: 'baz',
value: undefined,
},
],
},
Expand All @@ -187,8 +190,8 @@ However, with the help of <Link href="/api/flatten/">`flatten`</Link> the issues
```ts
{
nested: {
key: ['Value of "key" is missing.'],
'nested.key': ['Value of "nested.key" is missing.']
}
}
foo: ['Value of "foo" is missing.'],
'bar.baz': ['Value of "bar.baz" is missing.'],
},
};
```

0 comments on commit 65f0e59

Please sign in to comment.