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

undefined and unkown are marked as optional #242

Closed
emilgpa opened this issue Nov 3, 2023 · 6 comments
Closed

undefined and unkown are marked as optional #242

emilgpa opened this issue Nov 3, 2023 · 6 comments
Assignees
Labels
bug Something isn't working priority This has priority

Comments

@emilgpa
Copy link

emilgpa commented Nov 3, 2023

For example, with the follow schema:

export const mySchema = object({
    value: unknown(),
    checked: boolean(),
})

valibot returns as:

const mySchema: ObjectSchema<{
    value: UnknownSchema<unknown>;
    checked: BooleanSchema<boolean>;
}, undefined, {
    checked: boolean;
    value?: unknown;
}>

and

type H = Output<typeof mySchema>

is equal to

type H = {
    checked: boolean;
    value?: unknown;
}

but it should be:

type H = {
    checked: boolean;
    value: unknown;
}
@fabian-hiller
Copy link
Owner

Thanks a lot for creating this issue. I will fix that as soon as possible.

@fabian-hiller fabian-hiller self-assigned this Nov 3, 2023
@fabian-hiller fabian-hiller added the bug Something isn't working label Nov 3, 2023
@fabian-hiller
Copy link
Owner

I have now investigated the problem. Zod behaves the same way as Valibot, and theoretically it is not completely wrong, since any and unknown also include undefined. However, it would be better if entries were only marked as optional with a question mark when using optional because there is of course an difference between an undefined and optional entry. I will investigate this further.

@fabian-hiller fabian-hiller added the priority This has priority label Nov 19, 2023
@fabian-hiller
Copy link
Owner

Should I mark a field as optional only if optional is used or also with nullish?

@emilgpa
Copy link
Author

emilgpa commented Nov 19, 2023

In my opinion, it should be only if optional is used. The other one, nullish, I would leave only to mark the field as null or undefined

@fabian-hiller
Copy link
Owner

fabian-hiller commented Dec 8, 2023

This issue will be solved in the next minor version of Valibot.

@fabian-hiller
Copy link
Owner

v0.23.0 is now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority This has priority
Projects
None yet
Development

No branches or pull requests

2 participants