Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions source/conditional-pick-deep.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type BooleanPick = ConditionalPickDeep<Example, boolean | undefined>;
//=> {c: {e: {g?: boolean}; j: boolean}}

type NumberPick = ConditionalPickDeep<Example, number>;
//=> {}
//=> never

type StringOrBooleanPick = ConditionalPickDeep<Example, string | boolean>;
//=> {
Expand All @@ -99,11 +99,13 @@ export type ConditionalPickDeep<
Type,
Condition,
Options extends ConditionalPickDeepOptions = {},
> = _ConditionalPickDeep<
> = _NeverIfEmpty<_ConditionalPickDeep<
Type,
Condition,
ApplyDefaultOptions<ConditionalPickDeepOptions, DefaultConditionalPickDeepOptions, Options>
>;
>>;

type _NeverIfEmpty<Type> = Type extends EmptyObject ? never : Type;

type _ConditionalPickDeep<
Type,
Expand Down
10 changes: 9 additions & 1 deletion test-d/conditional-pick-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ declare const emptyPick: ConditionalPickDeep<Example, 'abcdefg'>;
expectType<{never: never}>(emptyPick);

declare const emptyEqualityPick: ConditionalPickDeep<Example, 'abcdefg', {condition: 'equality'}>;
expectType<{}>(emptyEqualityPick);
expectType<never>(emptyEqualityPick);

// Returns `never` when no keys match the condition
declare const noMatchingKeys: ConditionalPickDeep<{a: string; b: number}, boolean>;
expectType<never>(noMatchingKeys);

// Union with no common properties
declare const unionNoCommon: ConditionalPickDeep<{a: string} | {b: string}, string>;
expectType<{a: string} | {b: string}>(unionNoCommon);

declare const stringOrBooleanPick: ConditionalPickDeep<Example, string | boolean>;
expectType<{
Expand Down