ConditionalPickDeep: Fix returning {} instead of never when no keys match#1360
Merged
sindresorhus merged 3 commits intosindresorhus:mainfrom Feb 14, 2026
Merged
Conversation
sindresorhus
approved these changes
Feb 9, 2026
som-sm
requested changes
Feb 12, 2026
source/conditional-pick-deep.d.ts
Outdated
| >; | ||
| >>; | ||
|
|
||
| type _NeverIfEmpty<Type> = [keyof Type] extends [never] ? never : Type; |
Collaborator
There was a problem hiding this comment.
This is incorrect, because keyof Type would be never even for unions with no common properties. For example, ConditionalPickDeep<{a: string} | {b: string}>, string> should return {a: string} | {b: string}, but with this change it returns never.
Suggested change
| type _NeverIfEmpty<Type> = [keyof Type] extends [never] ? never : Type; | |
| type _NeverIfEmpty<Type> = Type extends EmptyObject ? never : Type; |
The above is better because it lets Type distribute, and EmptyObject is preferable to keyof Type since EmptyObject is already used to achieve the same behavior in nested cases.
type-fest/source/conditional-pick-deep.d.ts
Line 118 in 3995003
Contributor
Author
There was a problem hiding this comment.
Good catch, fixed. Also added a test for the union case with no common properties.
som-sm
approved these changes
Feb 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1358
Summary
Conditionat any depth,ConditionalPickDeeppreviously returned{}(empty object type). This allowed any properties to be assigned without type errors._NeverIfEmptyhelper that checks if the result has no keys and returnsneverin that case. This is applied only at the top level to avoid interfering with the internal recursiveEmptyObjectexclusion logic.Note
This is the deep variant of the same issue fixed in #1359 for
ConditionalPick.