fix: deepkeyandvalue behavior in union types#2057
fix: deepkeyandvalue behavior in union types#2057mdm317 wants to merge 4 commits intoTanStack:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 81806f8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| ? [NonNullable<V>] extends [never] | ||
| ? never |
There was a problem hiding this comment.
Since the previous behavior inferred never when the value was nullish,
the changes were updated to continue inferring never for nullish value types.
| export type DeepKeysOfNonNullableType<TData, TValue> = | ||
| ExtractByNonNullableValue<DeepKeysAndValues<TData>, TValue>['key'] |
There was a problem hiding this comment.
After changing DeepKeysAndValues to include nullish values, a bug was introduced in the group API when using DeepKeysOfType.
When the value type is nullish, it previously evaluated as:
Extract<never, nullish | TValue>
However, after the change, it became:
Extract<nullish, nullish | TValue>
which now returns nullish.
To resolve this issue, I implemented a new utility type to correctly infer TFields in the group API.
🎯 Changes
fixes #1813
Fix DeepKeysAndValues to return nullish values instead of never when the value type is nullish
ts playground
Due to the above change, I replaced DeepKeysOfType with DeepKeysOfNonNullableType in the group API.
✅ Checklist
pnpm test:pr.🚀 Release Impact
Change