@@ -6959,7 +6959,10 @@ namespace ts {
6959
6959
}
6960
6960
6961
6961
function createSignatureInstantiation(signature: Signature, typeArguments: Type[]): Signature {
6962
- return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), /*eraseTypeParameters*/ true);
6962
+ return instantiateSignature(signature, createSignatureTypeMapper(signature, typeArguments), /*eraseTypeParameters*/ true);
6963
+ }
6964
+ function createSignatureTypeMapper(signature: Signature, typeArguments: Type[]): TypeMapper {
6965
+ return createTypeMapper(signature.typeParameters, typeArguments);
6963
6966
}
6964
6967
6965
6968
function getErasedSignature(signature: Signature): Signature {
@@ -11419,8 +11422,8 @@ namespace ts {
11419
11422
}
11420
11423
}
11421
11424
11422
- function createInferenceContext(typeParameters: TypeParameter[], signature: Signature, flags: InferenceFlags, compareTypes?: TypeComparer, baseInferences?: InferenceInfo[]): InferenceContext {
11423
- const inferences = baseInferences ? map(baseInferences, cloneInferenceInfo) : map(typeParameters, createInferenceInfo);
11425
+ function createInferenceContext(typeParameters: TypeParameter[], signature: Signature | undefined , flags: InferenceFlags, compareTypes?: TypeComparer, baseInferences?: InferenceInfo[]): InferenceContext {
11426
+ const inferences = baseInferences ? baseInferences. map(cloneInferenceInfo) : typeParameters. map(createInferenceInfo);
11424
11427
const context = mapper as InferenceContext;
11425
11428
context.typeParameters = typeParameters;
11426
11429
context.signature = signature;
@@ -16409,15 +16412,23 @@ namespace ts {
16409
16412
return isValidPropertyAccessWithType(node, node.expression, property.escapedName, type)
16410
16413
&& (!(property.flags & SymbolFlags.Method) || isValidMethodAccess(property, type));
16411
16414
}
16412
- function isValidMethodAccess(method: Symbol, type : Type) {
16415
+ function isValidMethodAccess(method: Symbol, actualThisType : Type): boolean {
16413
16416
const propType = getTypeOfFuncClassEnumModule(method);
16414
16417
const signatures = getSignaturesOfType(getNonNullableType(propType), SignatureKind.Call);
16415
16418
Debug.assert(signatures.length !== 0);
16416
16419
return signatures.some(sig => {
16417
- const thisType = getThisTypeOfSignature(sig);
16418
- return !thisType || isTypeAssignableTo(type, thisType );
16420
+ const signatureThisType = getThisTypeOfSignature(sig);
16421
+ return !signatureThisType || isTypeAssignableTo(actualThisType, getInstantiatedSignatureThisType(sig, signatureThisType, actualThisType) );
16419
16422
});
16420
16423
}
16424
+ function getInstantiatedSignatureThisType(sig: Signature, signatureThisType: Type, actualThisType: Type): Type {
16425
+ if (!sig.typeParameters) {
16426
+ return signatureThisType;
16427
+ }
16428
+ const context = createInferenceContext(sig.typeParameters, sig, InferenceFlags.None);
16429
+ inferTypes(context.inferences, actualThisType, signatureThisType);
16430
+ return instantiateType(signatureThisType, createSignatureTypeMapper(sig, getInferredTypes(context)));
16431
+ }
16421
16432
16422
16433
function isValidPropertyAccessWithType(
16423
16434
node: PropertyAccessExpression | QualifiedName,
0 commit comments