Skip to content

Skip method this type validity filter for objects with more than 20 members #28692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ namespace ts {
const node = getParseTreeNode(nodeIn, isPropertyAccessOrQualifiedNameOrImportTypeNode);
return !!node && isValidPropertyAccess(node, escapeLeadingUnderscores(propertyName));
},
isValidPropertyAccessForCompletions: (nodeIn, type, property) => {
isValidPropertyAccessForCompletions: (nodeIn, type, property, skipMethodCheck) => {
const node = getParseTreeNode(nodeIn, isPropertyAccessExpression);
return !!node && isValidPropertyAccessForCompletions(node, type, property);
return !!node && isValidPropertyAccessForCompletions(node, type, property, skipMethodCheck);
},
getSignatureFromDeclaration: declarationIn => {
const declaration = getParseTreeNode(declarationIn, isFunctionLike);
Expand Down Expand Up @@ -19083,9 +19083,9 @@ namespace ts {
}
}

function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode, type: Type, property: Symbol): boolean {
function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode, type: Type, property: Symbol, skipMethodCheck: boolean): boolean {
return isValidPropertyAccessWithType(node, node.kind !== SyntaxKind.ImportType && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type)
&& (!(property.flags & SymbolFlags.Method) || isValidMethodAccess(property, type));
&& (!(property.flags & SymbolFlags.Method) || (skipMethodCheck || isValidMethodAccess(property, type)));
}
function isValidMethodAccess(method: Symbol, actualThisType: Type): boolean {
const propType = getTypeOfPropertyOfType(actualThisType, method.escapedName)!;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3103,7 +3103,7 @@ namespace ts {
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined;
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName | ImportTypeNode, propertyName: string): boolean;
/** Exclude accesses to private properties or methods with a `this` parameter that `type` doesn't satisfy. */
/* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode, type: Type, property: Symbol): boolean;
/* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode, type: Type, property: Symbol, skipMethodCheck: boolean): boolean;
/** Follow all aliases to get the original symbol. */
getAliasedSymbol(symbol: Symbol): Symbol;
/** Follow a *single* alias to get the immediately aliased symbol. */
Expand Down
5 changes: 3 additions & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,9 @@ namespace ts.Completions {
symbols.push(...getPropertiesForCompletion(type, typeChecker));
}
else {
for (const symbol of type.getApparentProperties()) {
if (typeChecker.isValidPropertyAccessForCompletions(node.kind === SyntaxKind.ImportType ? <ImportTypeNode>node : <PropertyAccessExpression>node.parent, type, symbol)) {
const props = type.getApparentProperties();
for (const symbol of props) {
if (typeChecker.isValidPropertyAccessForCompletions(node.kind === SyntaxKind.ImportType ? <ImportTypeNode>node : <PropertyAccessExpression>node.parent, type, symbol, props.length > 20)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make 20 a constant for better readability and maintainability

addPropertySymbol(symbol);
}
}
Expand Down