Skip to content

Correct order for null field - Fixes #1584#1610

Merged
stijnvanhulle merged 2 commits intokubb-labs:mainfrom
lambdank:patch-1
Mar 24, 2025
Merged

Correct order for null field - Fixes #1584#1610
stijnvanhulle merged 2 commits intokubb-labs:mainfrom
lambdank:patch-1

Conversation

@lambdank
Copy link
Contributor

@lambdank lambdank commented Mar 21, 2025

Hi 👋
I've experienced the bug #1584 as well, and had quick glance at the code.
It seems that null has the lowest sort order, and thus always comes last. But this seems to be an issue, since keywords that generates methods should always come after keywords that generate objects. Since null produces an object and optional produces a method, the current result is .optional()z.null().
The fix seems to be to move null above the method keywords in the sorting.

Feel free to merge this pull request, perform the fix yourselves or reject it if I have misunderstood something.

I really appreciate this project a lot and I'm very grateful for its existence. Feel free to reach out to me, if I can help with anything further.

@changeset-bot
Copy link

changeset-bot bot commented Mar 21, 2025

⚠️ No Changeset found

Latest commit: e69801a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@quintal-william
Copy link

Thank you for picking this up!! 👏🏼 Lets hope it gets merged soon 😄

@stijnvanhulle
Copy link
Collaborator

@lambdank Indeed you are right here, null should always be last because in the case of a string/number it should be added as last property instead of in the beginning of the array. Thanks for taking this up, this will be added soon as fix for Kubb.

@stijnvanhulle
Copy link
Collaborator

@all-contributors please add @lambdank for code

@stijnvanhulle stijnvanhulle linked an issue Mar 24, 2025 that may be closed by this pull request
@stijnvanhulle stijnvanhulle merged commit c0687d3 into kubb-labs:main Mar 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional null field results in Zod schema syntax error

3 participants