Skip to content

Commit 4f490d2

Browse files
fix: Overload cases
1 parent 8a7056b commit 4f490d2

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

source/internal/type.d.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,19 @@ type RecurseUniqueUnionDeep<U> =
198198
: U extends UnknownArray
199199
? InternalUniqueUnionDeep<U>
200200
: U extends Lambda
201-
// `Parametes` and `ReturnType` results are possible to be object or lambda; both should be passed into `UniqueUnionDeep`.
202-
? (...args: UniqueUnionDeep<Parameters<U>> extends infer A extends any[] ? A : never) => (UniqueUnionDeep<ReturnType<U>>)
201+
? IsNever<keyof U> extends true
202+
// `Parametes` and `ReturnType` results are possible to be object or lambda; both should be passed into `UniqueUnionDeep`.
203+
? HasMultipleCallSignatures<U> extends true
204+
? U
205+
: (...args: UniqueUnionDeep<Parameters<U>> extends infer A extends any[] ? A : never) => (UniqueUnionDeep<ReturnType<U>>)
206+
: U
203207
: U;
208+
204209
/**
205210
Note: Wrapping this with `Simplify`, `test-d/exact.ts` fails in "Spec: recursive type with union".
206211
*/
207-
type InternalUniqueUnionDeep<U extends object> = {[K in keyof U]: UniqueUnion<RecurseUniqueUnionDeep<U[K]>>};
212+
type InternalUniqueUnionDeep<U extends object> =
213+
{[K in keyof U]: UniqueUnion<RecurseUniqueUnionDeep<U[K]>>};
208214

209215
type Lambda = ((...args: any[]) => any);
210216

test-d/is-equal.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ expectType<true>({} as IsEqual<AnyLambda, AnyLambda>);
6363
expectType<false>({} as IsEqual<AnyLambda, NumberLambda>);
6464
expectType<false>({} as IsEqual<NumberLambda, AnyLambda>);
6565

66+
// Branded Type
67+
expectType<false>({} as IsEqual<1 & {foo?: 1}, 1>);
68+
expectType<true>({} as IsEqual<1 & {foo?: 1}, 1 & {foo?: 1}>);
69+
expectType<false>({} as IsEqual<{bar: 'a'} & {foo?: 1}, {bar: 'a'}>);
70+
expectType<false>({} as IsEqual<((value: number) => void) & {foo?: 1}, (value: number) => void>);
71+
72+
// Overload
73+
expectType<false>({} as IsEqual<{(value: 'a'): 1; (value: string): 1}, (value: string) => 1>);
74+
expectType<false>({} as IsEqual<{(value: 'a'): 1; (value: string): 1; key: 'value'}, (value: string) => 1>);
75+
expectType<false>({} as IsEqual<{(value: 'a'): 1; (value: string): 1; key: 'value'}, {(value: string): 1; key: 'value'}>);
76+
6677
// Lambda: Identical Union and Intersection cases.
6778
expectType<true>({} as IsEqual<SpecificNumericLambda & SpecificNumericLambda, SpecificNumericLambda>); // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
6879
expectType<true>({} as IsEqual<SpecificNumericLambda | SpecificNumericLambda, SpecificNumericLambda>); // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents

0 commit comments

Comments
 (0)