Merge pull request #31377 from microsoft/noThisParameterFiltering

Revert this-parameter filtering in completions
This commit is contained in:
Anders Hejlsberg 2019-05-13 17:07:05 -07:00 committed by GitHub
commit 70950cb934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 39 deletions

View File

@ -20386,25 +20386,8 @@ namespace ts {
}
function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean {
return isValidPropertyAccessWithType(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type)
&& (!(property.flags & SymbolFlags.Method) || isValidMethodAccess(property, type));
}
function isValidMethodAccess(method: Symbol, actualThisType: Type): boolean {
const propType = getTypeOfPropertyOfType(actualThisType, method.escapedName)!;
const signatures = getSignaturesOfType(getNonNullableType(propType), SignatureKind.Call);
Debug.assert(signatures.length !== 0);
return signatures.some(sig => {
const signatureThisType = getThisTypeOfSignature(sig);
return !signatureThisType || isTypeAssignableTo(actualThisType, getInstantiatedSignatureThisType(sig, signatureThisType, actualThisType));
});
}
function getInstantiatedSignatureThisType(sig: Signature, signatureThisType: Type, actualThisType: Type): Type {
if (!sig.typeParameters) {
return signatureThisType;
}
const context = createInferenceContext(sig.typeParameters, sig, InferenceFlags.None);
inferTypes(context.inferences, actualThisType, signatureThisType);
return instantiateType(signatureThisType, createSignatureTypeMapper(sig, getInferredTypes(context)));
return isValidPropertyAccessWithType(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type);
// Previously we validated the 'this' type of methods but this adversely affected performance. See #31377 for more context.
}
function isValidPropertyAccessWithType(

View File

@ -1,20 +0,0 @@
/// <reference path='fourslash.ts'/>
////class A<T> {
//// value: T; // Make the type parameter actually matter
//// ms(this: A<string>) {}
//// mo(this: A<{}>) {}
//// mt(this: A<T>) {}
//// mp<P>(this: A<P>) {}
//// mps<P extends string>(this: A<P>) {}
////}
////
////const s = new A<string>();
////const n = new A<number>();
////s./*s*/;
////n./*n*/;
verify.completions(
{ marker: "s", exact: ["value", "ms", "mo", "mt", "mp", "mps"] },
{ marker: "n", exact: ["value", "mo", "mt", "mp"] },
);