Skip to content

Commit 346fe2d

Browse files
committed
Revert "Merge pull request microsoft#32049 from microsoft/noDuplicateIntersectionSignatures"
This reverts commit f89165d, reversing changes made to 410b717.
1 parent 0dbaef5 commit 346fe2d

12 files changed

+17
-230
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7404,8 +7404,8 @@ namespace ts {
74047404
function resolveIntersectionTypeMembers(type: IntersectionType) {
74057405
// The members and properties collections are empty for intersection types. To get all properties of an
74067406
// intersection type use getPropertiesOfType (only the language service uses this).
7407-
let callSignatures: Signature[] | undefined;
7408-
let constructSignatures: Signature[] | undefined;
7407+
let callSignatures: ReadonlyArray<Signature> = emptyArray;
7408+
let constructSignatures: ReadonlyArray<Signature> = emptyArray;
74097409
let stringIndexInfo: IndexInfo | undefined;
74107410
let numberIndexInfo: IndexInfo | undefined;
74117411
const types = type.types;
@@ -7427,22 +7427,13 @@ namespace ts {
74277427
return clone;
74287428
});
74297429
}
7430-
constructSignatures = appendSignatures(constructSignatures, signatures);
7430+
constructSignatures = concatenate(constructSignatures, signatures);
74317431
}
7432-
callSignatures = appendSignatures(callSignatures, getSignaturesOfType(t, SignatureKind.Call));
7432+
callSignatures = concatenate(callSignatures, getSignaturesOfType(t, SignatureKind.Call));
74337433
stringIndexInfo = intersectIndexInfos(stringIndexInfo, getIndexInfoOfType(t, IndexKind.String));
74347434
numberIndexInfo = intersectIndexInfos(numberIndexInfo, getIndexInfoOfType(t, IndexKind.Number));
74357435
}
7436-
setStructuredTypeMembers(type, emptySymbols, callSignatures || emptyArray, constructSignatures || emptyArray, stringIndexInfo, numberIndexInfo);
7437-
}
7438-
7439-
function appendSignatures(signatures: Signature[] | undefined, newSignatures: readonly Signature[]) {
7440-
for (const sig of newSignatures) {
7441-
if (!signatures || every(signatures, s => !compareSignaturesIdentical(s, sig, /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ false, compareTypesIdentical))) {
7442-
signatures = append(signatures, sig);
7443-
}
7444-
}
7445-
return signatures;
7436+
setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
74467437
}
74477438

74487439
/**
@@ -14633,25 +14624,20 @@ namespace ts {
1463314624
if (!(isMatchingSignature(source, target, partialMatch))) {
1463414625
return Ternary.False;
1463514626
}
14636-
// Check that the two signatures have the same number of type parameters.
14627+
// Check that the two signatures have the same number of type parameters. We might consider
14628+
// also checking that any type parameter constraints match, but that would require instantiating
14629+
// the constraints with a common set of type arguments to get relatable entities in places where
14630+
// type parameters occur in the constraints. The complexity of doing that doesn't seem worthwhile,
14631+
// particularly as we're comparing erased versions of the signatures below.
1463714632
if (length(source.typeParameters) !== length(target.typeParameters)) {
1463814633
return Ternary.False;
1463914634
}
14640-
// Check that type parameter constraints and defaults match. If they do, instantiate the source
14641-
// signature with the type parameters of the target signature and continue the comparison.
14642-
if (target.typeParameters) {
14643-
const mapper = createTypeMapper(source.typeParameters!, target.typeParameters);
14644-
for (let i = 0; i < target.typeParameters.length; i++) {
14645-
const s = source.typeParameters![i];
14646-
const t = target.typeParameters[i];
14647-
if (!(s === t || compareTypes(instantiateType(getConstraintFromTypeParameter(s), mapper) || unknownType, getConstraintFromTypeParameter(t) || unknownType) &&
14648-
compareTypes(instantiateType(getDefaultFromTypeParameter(s), mapper) || unknownType, getDefaultFromTypeParameter(t) || unknownType))) {
14649-
return Ternary.False;
14650-
}
14651-
}
14652-
source = instantiateSignature(source, mapper, /*eraseTypeParameters*/ true);
14653-
}
14635+
// Spec 1.0 Section 3.8.3 & 3.8.4:
14636+
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
14637+
source = getErasedSignature(source);
14638+
target = getErasedSignature(target);
1465414639
let result = Ternary.True;
14640+
1465514641
if (!ignoreThisTypes) {
1465614642
const sourceThisType = getThisTypeOfSignature(source);
1465714643
if (sourceThisType) {
@@ -14665,6 +14651,7 @@ namespace ts {
1466514651
}
1466614652
}
1466714653
}
14654+
1466814655
const targetLen = getParameterCount(target);
1466914656
for (let i = 0; i < targetLen; i++) {
1467014657
const s = getTypeAtPosition(source, i);

tests/baselines/reference/genericSignatureIdentity.errors.txt

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/baselines/reference/identityForSignaturesWithTypeParametersAndAny.errors.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts(2,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '<T, U>(x: T, y: U) => T', but here has type '<T, U>(x: any, y: any) => any'.
21
tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts(5,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'g' must be of type '<T, U>(x: T, y: U) => T', but here has type '<T>(x: any, y: any) => any'.
32
tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts(8,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'h' must be of type '<T, U>(x: T, y: U) => T', but here has type '(x: any, y: any) => any'.
43
tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts(11,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type '<T, U>(x: T, y: U) => T', but here has type '<T, U>(x: any, y: string) => any'.
54
tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts(14,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'j' must be of type '<T, U>(x: T, y: U) => T', but here has type '<T, U>(x: any, y: any) => string'.
65

76

8-
==== tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts (5 errors) ====
7+
==== tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts (4 errors) ====
98
var f: <T, U>(x: T, y: U) => T;
109
var f: <T, U>(x: any, y: any) => any;
11-
~
12-
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '<T, U>(x: T, y: U) => T', but here has type '<T, U>(x: any, y: any) => any'.
13-
!!! related TS6203 tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts:1:5: 'f' was also declared here.
1410

1511
var g: <T, U>(x: T, y: U) => T;
1612
var g: <T>(x: any, y: any) => any;

tests/baselines/reference/identityForSignaturesWithTypeParametersSwitched.errors.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/baselines/reference/keyofAndIndexedAccess2.errors.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,4 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23
237237
type Baz<T, Q extends Foo<T>> = { [K in keyof Q]: T[Q[K]] };
238238

239239
type Qux<T, Q extends Bar<T>> = { [K in keyof Q]: T[Q[K]["0"]] };
240-
241-
// Repro from #32038
242-
243-
const actions = ['resizeTo', 'resizeBy'] as const;
244-
for (const action of actions) {
245-
window[action] = (x, y) => {
246-
window[action](x, y);
247-
}
248-
}
249240

tests/baselines/reference/keyofAndIndexedAccess2.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,6 @@ type Bar<T> = { [key: string]: { [K in keyof T]: [K] }[keyof T] };
156156
type Baz<T, Q extends Foo<T>> = { [K in keyof Q]: T[Q[K]] };
157157

158158
type Qux<T, Q extends Bar<T>> = { [K in keyof Q]: T[Q[K]["0"]] };
159-
160-
// Repro from #32038
161-
162-
const actions = ['resizeTo', 'resizeBy'] as const;
163-
for (const action of actions) {
164-
window[action] = (x, y) => {
165-
window[action](x, y);
166-
}
167-
}
168159

169160

170161
//// [keyofAndIndexedAccess2.js]
@@ -262,10 +253,3 @@ export class c {
262253
this["a"] = "b";
263254
}
264255
}
265-
// Repro from #32038
266-
const actions = ['resizeTo', 'resizeBy'];
267-
for (const action of actions) {
268-
window[action] = (x, y) => {
269-
window[action](x, y);
270-
};
271-
}

tests/baselines/reference/keyofAndIndexedAccess2.symbols

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -564,26 +564,3 @@ type Qux<T, Q extends Bar<T>> = { [K in keyof Q]: T[Q[K]["0"]] };
564564
>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 156, 11))
565565
>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 156, 35))
566566

567-
// Repro from #32038
568-
569-
const actions = ['resizeTo', 'resizeBy'] as const;
570-
>actions : Symbol(actions, Decl(keyofAndIndexedAccess2.ts, 160, 5))
571-
572-
for (const action of actions) {
573-
>action : Symbol(action, Decl(keyofAndIndexedAccess2.ts, 161, 10))
574-
>actions : Symbol(actions, Decl(keyofAndIndexedAccess2.ts, 160, 5))
575-
576-
window[action] = (x, y) => {
577-
>window : Symbol(window, Decl(lib.dom.d.ts, --, --))
578-
>action : Symbol(action, Decl(keyofAndIndexedAccess2.ts, 161, 10))
579-
>x : Symbol(x, Decl(keyofAndIndexedAccess2.ts, 162, 19))
580-
>y : Symbol(y, Decl(keyofAndIndexedAccess2.ts, 162, 21))
581-
582-
window[action](x, y);
583-
>window : Symbol(window, Decl(lib.dom.d.ts, --, --))
584-
>action : Symbol(action, Decl(keyofAndIndexedAccess2.ts, 161, 10))
585-
>x : Symbol(x, Decl(keyofAndIndexedAccess2.ts, 162, 19))
586-
>y : Symbol(y, Decl(keyofAndIndexedAccess2.ts, 162, 21))
587-
}
588-
}
589-

tests/baselines/reference/keyofAndIndexedAccess2.types

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -540,35 +540,3 @@ type Baz<T, Q extends Foo<T>> = { [K in keyof Q]: T[Q[K]] };
540540
type Qux<T, Q extends Bar<T>> = { [K in keyof Q]: T[Q[K]["0"]] };
541541
>Qux : Qux<T, Q>
542542

543-
// Repro from #32038
544-
545-
const actions = ['resizeTo', 'resizeBy'] as const;
546-
>actions : readonly ["resizeTo", "resizeBy"]
547-
>['resizeTo', 'resizeBy'] as const : readonly ["resizeTo", "resizeBy"]
548-
>['resizeTo', 'resizeBy'] : readonly ["resizeTo", "resizeBy"]
549-
>'resizeTo' : "resizeTo"
550-
>'resizeBy' : "resizeBy"
551-
552-
for (const action of actions) {
553-
>action : "resizeTo" | "resizeBy"
554-
>actions : readonly ["resizeTo", "resizeBy"]
555-
556-
window[action] = (x, y) => {
557-
>window[action] = (x, y) => { window[action](x, y); } : (x: number, y: number) => void
558-
>window[action] : ((x: number, y: number) => void) & ((x: number, y: number) => void) & ((x: number, y: number) => void) & ((x: number, y: number) => void)
559-
>window : Window & typeof globalThis
560-
>action : "resizeTo" | "resizeBy"
561-
>(x, y) => { window[action](x, y); } : (x: number, y: number) => void
562-
>x : number
563-
>y : number
564-
565-
window[action](x, y);
566-
>window[action](x, y) : void
567-
>window[action] : (((x: number, y: number) => void) & ((x: number, y: number) => void)) | (((x: number, y: number) => void) & ((x: number, y: number) => void))
568-
>window : Window & typeof globalThis
569-
>action : "resizeTo" | "resizeBy"
570-
>x : number
571-
>y : number
572-
}
573-
}
574-

tests/baselines/reference/promiseIdentity.errors.txt

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/baselines/reference/promiseIdentityWithAny.errors.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/baselines/reference/promiseIdentityWithConstraints.errors.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,3 @@ type Bar<T> = { [key: string]: { [K in keyof T]: [K] }[keyof T] };
158158
type Baz<T, Q extends Foo<T>> = { [K in keyof Q]: T[Q[K]] };
159159

160160
type Qux<T, Q extends Bar<T>> = { [K in keyof Q]: T[Q[K]["0"]] };
161-
162-
// Repro from #32038
163-
164-
const actions = ['resizeTo', 'resizeBy'] as const;
165-
for (const action of actions) {
166-
window[action] = (x, y) => {
167-
window[action](x, y);
168-
}
169-
}

0 commit comments

Comments
 (0)