Skip to content

fix: do not treat falsy distinct field as no fields - #159

Open
thetutlage wants to merge 1 commit into
4.xfrom
fix/distinct-zero-field
Open

thetutlage wants to merge 1 commit into
4.xfrom
fix/distinct-zero-field

Conversation

@thetutlage

Copy link
Copy Markdown
Contributor

helpers.isDistinct used if (!fields) to detect that no fields were provided. A falsy field like 0 therefore took the no-fields path, which compares items by reference, so duplicate objects were never reported:

vine.array(vine.object({ '0': vine.string() })).distinct(0 as any)
// [{ 0: 'a' }, { 0: 'a' }] passed validation

The check is now explicit (undefined, null or ''). An empty string still means "no fields", so its behavior does not change.

Numeric fields are outside the TypeScript signature, but JavaScript callers and vine.helpers.isDistinct can still reach this path. Numeric object keys are already supported (see the allow object keys to be numeric regression test).

Notes

🤖 Generated with Claude Code

isDistinct used a truthy check to detect missing fields, so a numeric
field like 0 fell into the no-fields path. That path compares items by
reference, which meant duplicate objects were never reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant