diff --git a/source/conditional-pick.d.ts b/source/conditional-pick.d.ts index 66f908b92..e7db8f6ec 100644 --- a/source/conditional-pick.d.ts +++ b/source/conditional-pick.d.ts @@ -1,4 +1,5 @@ import type {ConditionalKeys} from './conditional-keys.d.ts'; +import type {IsNever} from './is-never.d.ts'; /** Pick keys from the shape that matches the given `Condition`. @@ -38,9 +39,10 @@ type StringKeysOnly = ConditionalPick; @category Object */ -export type ConditionalPick = Pick< - Base, - ConditionalKeys ->; +export type ConditionalPick = ConditionalKeys extends infer Keys + ? IsNever extends true + ? never + : Pick + : never; export {}; diff --git a/test-d/conditional-pick.ts b/test-d/conditional-pick.ts index a3f40141b..bd2c5220f 100644 --- a/test-d/conditional-pick.ts +++ b/test-d/conditional-pick.ts @@ -26,3 +26,10 @@ expectType<{name: string; successes: number; failures: bigint}>(awesomeCondition declare const exampleConditionalPickWithUndefined: ConditionalPick; expectType<{a: string; c?: string}>(exampleConditionalPickWithUndefined); + +// Returns `never` when no keys match the condition +declare const noMatchingKeys: ConditionalPick; +expectType(noMatchingKeys); + +declare const noMatchingKeys2: ConditionalPick<{a: string; b: number}, boolean>; +expectType(noMatchingKeys2);