Skip to content

Conversation

@weswigham
Copy link
Member

Fixes #23285 specifically by limiting the number of properties we filter methods on to 20 (so if an object has > 20 members, we no longer filter invalid method calls from the completion list), though the underlying issue remains. It's also questionable if the filtering is even really correct, since using the member in a non-calling fashion is still acceptable - the choice to filter methods at all feels somewhat pragmatic.

That underlying issue is that every anonymous type instantiation is unique - so even though we're querying similar types across the ~300 this-type comparisons we perform, since the input anonymous types are differing identities, we repeat a lot of very similar work. Caching on signatures doesn't help here, since each comparison is triggered for a different signature. The issue is simply that if I have 200 methods with this: {item: T}, then every time we infer from {item: string} to {item: T} and instantiate T with string, we get a new overall type identity and need to perform a structural comparison, even though it's still just {item: string}.

Copy link
Member

@sheetalkamat sheetalkamat left a comment

Choose a reason for hiding this comment

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

Could this be confusing from user perspective? I am wondering what we are achieving anything significant through filtering. To me it seems the filtering helps when there are too many options but here we are limiting when there are fewer options so seems contradictory. Change looks good but will let @DanielRosenwasser comment on whether we should skip this type check all the time or with the condition you have.

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

@weswigham
Copy link
Member Author

It's probably worth noting that at least @rbuckton apparently has a library that relies on this filtering for more accurate method completions. :S

@weswigham
Copy link
Member Author

Superseded by #31377

@weswigham weswigham closed this May 13, 2019
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long running 'completions' request on TS project using lodash

2 participants