Skip to content

Commit 65f0e59

Browse files
Merge pull request #940 from EltonLobo07/doc/improve-issues-guide
improve `Flatten errors` section's (issues guide) example
2 parents 16f004c + 050072a commit 65f0e59

File tree

1 file changed

+18
-15
lines changed
  • website/src/routes/guides/(main-concepts)/issues

1 file changed

+18
-15
lines changed

website/src/routes/guides/(main-concepts)/issues/index.mdx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ description: >-
66
contributors:
77
- fabian-hiller
88
- BastiDood
9+
- EltonLobo07
910
---
1011

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

121122
const ObjectSchema = v.object({
122-
key: v.string('Value of "key" is missing.'),
123-
nested: v.object({
124-
key: v.string('Value of "nested.key" is missing.'),
123+
foo: v.string('Value of "foo" is missing.'),
124+
bar: v.object({
125+
baz: v.string('Value of "bar.baz" is missing.'),
125126
}),
126127
});
127128

128-
const result = v.safeParse(ObjectSchema, { nested: {} });
129+
const result = v.safeParse(ObjectSchema, { bar: {} });
129130

130131
if (result.issues) {
131132
console.log(v.flatten<typeof ObjectSchema>(result.issues));
@@ -142,15 +143,16 @@ The `result` returned in the code sample above this text contains the following
142143
input: undefined,
143144
expected: 'string',
144145
received: 'undefined',
145-
message: 'Value of "key" is missing.',
146+
message: 'Value of "foo" is missing.',
146147
path: [
147148
{
148149
type: 'object',
149150
origin: 'value',
150151
input: {
151-
nested: {},
152+
bar: {},
152153
},
153-
key: 'key',
154+
key: 'foo',
155+
value: undefined,
154156
},
155157
],
156158
},
@@ -160,22 +162,23 @@ The `result` returned in the code sample above this text contains the following
160162
input: undefined,
161163
expected: 'string',
162164
received: 'undefined',
163-
message: 'Value of "nested.key" is missing.',
165+
message: 'Value of "bar.baz" is missing.',
164166
path: [
165167
{
166168
type: 'object',
167169
origin: 'value',
168170
input: {
169-
nested: {},
171+
bar: {},
170172
},
171-
key: 'nested',
173+
key: 'bar',
172174
value: {},
173175
},
174176
{
175177
type: 'object',
176178
origin: 'value',
177179
input: {},
178-
key: 'key',
180+
key: 'baz',
181+
value: undefined,
179182
},
180183
],
181184
},
@@ -187,8 +190,8 @@ However, with the help of <Link href="/api/flatten/">`flatten`</Link> the issues
187190
```ts
188191
{
189192
nested: {
190-
key: ['Value of "key" is missing.'],
191-
'nested.key': ['Value of "nested.key" is missing.']
192-
}
193-
}
193+
foo: ['Value of "foo" is missing.'],
194+
'bar.baz': ['Value of "bar.baz" is missing.'],
195+
},
196+
};
194197
```

0 commit comments

Comments
 (0)