Skip to content
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

Property autocompletion includes Symbol when object has a well-known symbol as key #52268

Open
uhyo opened this issue Jan 17, 2023 · 2 comments
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this
Milestone

Comments

@uhyo
Copy link
Contributor

uhyo commented Jan 17, 2023

Bug Report

πŸ”Ž Search Terms

property autocompletion symbol well-known

πŸ•— Version & Regression Information

TypeScript 4.9.4

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about ?

⏯ Playground Link

Playground link with relevant code

Sorry but please note that I wasn't able to reproduce the issue on the playground. The issue was reproducible on my VSCode 1.74.3, with extensions disabled, and TypeScript 4.9.4.

πŸ’» Code

const obj = {
  field: 0,
  [Symbol.asyncIterator]() {}
};

obj.
//  ^autocompletion here

tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "strict": true
  },
  "include": ["index.ts"]
}

πŸ™ Actual behavior

Symbol is shown as a autocompletion candidate.

γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ 2023-01-17 11 06 07

Selecting it produces obj[Symbol] which isn't correct.

πŸ™‚ Expected behavior

Should offer Symbol.asyncIterator.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this Domain: Completion Lists The issue relates to showing completion lists in an editor labels Jan 19, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 19, 2023
@Andarist
Copy link
Contributor

The reason why it's not reproducible in the TS playground is that this depends on includeCompletionsWithInsertText: true user preference.

@Andarist
Copy link
Contributor

So it seems that adding Symbol is currently intentional (introduced in #23091 ):

// For a computed property with an accessible name like `Symbol.iterator`,
// we'll add a completion for the *name* `Symbol` instead of for the property.
// If this is e.g. [Symbol.iterator], add a completion for `Symbol`.

and this completion entry might be rejected conditionally based on includeCompletionsWithInsertText here:

if (insertText !== undefined && !preferences.includeCompletionsWithInsertText) {
return undefined;
}

I find the intention here somewhat questionable, especially since the cursor is put after the closing bracket (obj[Symbol]/**/). So you can't even immediately chain from Symbol after choosing that.

I think that at the very least the cursor's position should be different after chosing that completion but I agree with OP that it would be even better to suggest concrete symbols there (like Symbol.iterator, Symbol.asyncIterator, etc). Perhaps it's already implemented like that but I feel like those definitely should have the lowest possible priority~ assigned to them. Most people don't care about those so those should appear at the bottom of the list.

It would also be cool if the list could be filterable by the concrete name of the symbol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants