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

improve Flatten errors section's (issues guide) example #940

Merged

Conversation

EltonLobo07
Copy link
Contributor

The example under the Flatten errors section uses a nested key to define the object schema. This might confuse the readers, as the result returned by the flatten function might also use nested as a key to indicate nested issues.

Before:
image

After:
image

The example under the `Flatten errors` section uses a `nested` key to
define the object schema. This might confuse the readers, as the result
returned by the `flatten` function might also use `nested` as a key to
return nested issues.
Copy link

pkg-pr-new bot commented Nov 22, 2024

Open in Stackblitz

npm i https://pkg.pr.new/valibot@940

commit: 050072a

@fabian-hiller
Copy link
Owner

Another option would be to rename the keys to nested1 and nested2. What do you think?

@fabian-hiller fabian-hiller self-assigned this Nov 25, 2024
@fabian-hiller fabian-hiller added the documentation Improvements or additions to documentation label Nov 25, 2024
@EltonLobo07
Copy link
Contributor Author

I am not sure if I understand. We can't rename the key returned by the flatten method.
image
What we can do is rename the key of the example input object used (nested -> nestedObject or something else) to make it easier to understand the relation between the input and output. So we have the flexibility to change one object key. That means nested1 and nested2 won't make sense.

To provide more context: While reading the section, initially I was confused.
Input:
image
Output:
image
Why is key inside nested? In the input the outer key is not inside nested but in the output it is. But after a while I figured it was one of the standard keys returned by the flatten method.

I think we can improve this using a different name that is not one of the standard keys returned by the flatten method. What do you think?

@fabian-hiller
Copy link
Owner

Another option would be to rename the keys to nested1 and nested2. What do you think?

You are right. My previous comment doesn't make sense. Sorry about that.

It may be better to rename all the keys. What do you think? Here is an example:

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

@EltonLobo07
Copy link
Contributor Author

Renaming all of the keys is even better! Will update this PR shortly.

Update the key names to something else than the current so that the
reader is not confused after reading it.
make the displayed path items consistent by adding `value` keys
@fabian-hiller fabian-hiller merged commit 65f0e59 into fabian-hiller:main Dec 4, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants