Skip to content

bug: Incorrect Typescript completion with computed property name #54013

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
NikolasKomonen opened this issue Apr 25, 2023 · 3 comments · Fixed by #54067
Closed

bug: Incorrect Typescript completion with computed property name #54013

NikolasKomonen opened this issue Apr 25, 2023 · 3 comments · Fixed by #54067
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

@NikolasKomonen
Copy link

When doing completions where my interface uses computed property names, the completion result does not
show the correct completion items.

Test Code

const MyKeys = {
    KEY_1: 'key_1',
    KEY_2: 'key_2',
    KEY_3: 'key_3',
} as const

const MyKeys2 = {
    KEY_1: 'key_1',
    KEY_2: 'key_2',
    KEY_3: 'key_3',
} as const

interface MyInterface {
    [MyKeys2.KEY_1]: string,
    [MyKeys.KEY_2]: string,
    [MyKeys.KEY_3]: string
}

const myObj: MyInterface = {
    key_1: 'value_1',
    key_2: 'value_2',
    key_3: 'value_3',
}

myObj.

Current Incorrect Completion Result

Screen Shot 2023-04-25 at 2 53 45 PM

Expected

Instead I would expect 3 completion results:

  • key_1
  • key_2
  • key_3

Additional Findings

It looks like the first use of a specific const (MyKeys or MyKeys2) in the interface MyInterface is replaced with the wrong value, but all subsequent references (key_3) show up correctly

Version Info

Version: 1.77.3 (Universal)
Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710
Date: 2023-04-12T09:19:37.325Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Darwin arm64 21.6.0
Sandboxed: Yes

@mjbvz mjbvz transferred this issue from microsoft/vscode Apr 25, 2023
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Apr 25, 2023
@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Apr 25, 2023

This is correct behavior. If you complete the entry, you'll get an indexed access snippet:

myObj[MyKeys2.

which corresponds to the declaration form you used to write the object in the first place

@NikolasKomonen
Copy link
Author

@RyanCavanaugh thanks for the quick response. Makes sense to me that that is the intended use.

I'm wondering why keys_3 is shown in the example image? Would it make sense to only show the completion results MyKeys and MyKeys2 then?

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Apr 25, 2023
@RyanCavanaugh
Copy link
Member

Good point - I have no idea why it's mixing and matching there. Seems off.

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

Successfully merging a pull request may close this issue.

2 participants