@@ -14322,20 +14322,25 @@ namespace ts {
14322
14322
if (!(isMatchingSignature(source, target, partialMatch))) {
14323
14323
return Ternary.False;
14324
14324
}
14325
- // Check that the two signatures have the same number of type parameters. We might consider
14326
- // also checking that any type parameter constraints match, but that would require instantiating
14327
- // the constraints with a common set of type arguments to get relatable entities in places where
14328
- // type parameters occur in the constraints. The complexity of doing that doesn't seem worthwhile,
14329
- // particularly as we're comparing erased versions of the signatures below.
14325
+ // Check that the two signatures have the same number of type parameters.
14330
14326
if (length(source.typeParameters) !== length(target.typeParameters)) {
14331
14327
return Ternary.False;
14332
14328
}
14333
- // Spec 1.0 Section 3.8.3 & 3.8.4:
14334
- // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
14335
- source = getErasedSignature(source);
14336
- target = getErasedSignature(target);
14329
+ // Check that type parameter constraints and defaults match. If they do, instantiate the source
14330
+ // signature with the type parameters of the target signature and continue the comparison.
14331
+ if (target.typeParameters) {
14332
+ const mapper = createTypeMapper(source.typeParameters!, target.typeParameters);
14333
+ for (let i = 0; i < target.typeParameters.length; i++) {
14334
+ const s = source.typeParameters![i];
14335
+ const t = target.typeParameters[i];
14336
+ if (!(s === t || compareTypes(instantiateType(getConstraintFromTypeParameter(s), mapper) || unknownType, getConstraintFromTypeParameter(t) || unknownType) &&
14337
+ compareTypes(instantiateType(getDefaultFromTypeParameter(s), mapper) || unknownType, getDefaultFromTypeParameter(t) || unknownType))) {
14338
+ return Ternary.False;
14339
+ }
14340
+ }
14341
+ source = instantiateSignature(source, mapper, /*eraseTypeParameters*/ true);
14342
+ }
14337
14343
let result = Ternary.True;
14338
-
14339
14344
if (!ignoreThisTypes) {
14340
14345
const sourceThisType = getThisTypeOfSignature(source);
14341
14346
if (sourceThisType) {
@@ -14349,7 +14354,6 @@ namespace ts {
14349
14354
}
14350
14355
}
14351
14356
}
14352
-
14353
14357
const targetLen = getParameterCount(target);
14354
14358
for (let i = 0; i < targetLen; i++) {
14355
14359
const s = getTypeAtPosition(source, i);
0 commit comments