diff --git a/source/conditional-pick-deep.d.ts b/source/conditional-pick-deep.d.ts index dbc2a7da3..cdfcb2190 100644 --- a/source/conditional-pick-deep.d.ts +++ b/source/conditional-pick-deep.d.ts @@ -15,7 +15,7 @@ Assert the condition according to the {@link ConditionalPickDeepOptions.conditio */ type AssertCondition = Options['condition'] extends 'equality' ? IsEqual - : Type extends Condition + : [Type] extends [Condition] ? true : false; @@ -114,7 +114,7 @@ type _ConditionalPickDeep< > = ConditionalSimplifyDeep extends true ? Type[Key] - : IsPlainObject extends true + : IsPlainObject> extends true ? _ConditionalPickDeep : typeof conditionalPickDeepSymbol; }, (typeof conditionalPickDeepSymbol | undefined) | EmptyObject>, never, UnknownRecord>; diff --git a/test-d/conditional-pick-deep.ts b/test-d/conditional-pick-deep.ts index 29d429b45..eeba96ff1 100644 --- a/test-d/conditional-pick-deep.ts +++ b/test-d/conditional-pick-deep.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import type {ConditionalPickDeep} from '../index.d.ts'; +import type {ConditionalPickDeep, Paths} from '../index.d.ts'; declare class ClassA { public a: string; @@ -10,6 +10,11 @@ interface InterfaceA { a: number; } +enum TestEnum { + TEST1 = 'TEST1', + TEST2 = 'TEST2', +} + type Example = { optional?: boolean; optionalWithUndefined?: boolean | undefined; @@ -42,6 +47,15 @@ type Example = { }; }; +type EnumExample = { + enum: TestEnum; + string: string | null; +}; + +type UnionExample = { + a: string | null; +}; + declare const stringPick: ConditionalPickDeep; expectType<{ literal: 'foo'; @@ -158,3 +172,23 @@ expectType<{set: Set; never: never}>(setPick); declare const interfaceTest: ConditionalPickDeep; expectType<{interface: InterfaceA; never: never}>(interfaceTest); + +declare const enumPick: ConditionalPickDeep; +expectType<{enum: TestEnum}>(enumPick); + +expectType<'enum'>({} as Paths>); + +declare const unionPick: +ConditionalPickDeep; +expectType(unionPick); + +type NestedEnumExample = { + obj: { + value: TestEnum; + other: string | null; + }; +}; + +declare const nestedPick: +ConditionalPickDeep; +expectType<{obj: {value: TestEnum}}>(nestedPick);