zed
zed copied to clipboard
[TypeScript] Autocomplete in indexed access string literals erroneously adds method parameters
Summary
In TypeScript, autocomplete within string literals (used for indexed access types) erroneously suggests method calls with parameters instead of method names.
Steps to trigger the problem
I'am using vim mode, but it should be reproducable without it):
- Create a TypeScript file with the following code:
class MyClass {
sayHello(name: string) {
return `Hello, ${name}!`;
}
}
type Foo = MyClass["sayH"]
- Place the cursor after the
H - Activate autocomplete with
Ctrl+Space - Accept the suggestion
Actual Behavior:
Autocomplete inserts sayHello(name) into the string literal, resulting in:
type Foo = MyClass["sayHello(name)"]
Expected Behavior:
Autocomplete should insert only the method name sayHello into the string literal, as the context is a type declaration using indexed access syntax. The result should be:
type Foo = MyClass["sayHello"]
Notes:
The issue occurs specifically when autocompleting method names within string literals for indexed access types. The current behavior mistakenly treats the context as a method call (appending parameters) instead of a property name reference. This violates TypeScript’s syntax rules for indexed access types, where only the property name (not a method call) is valid.
Zed Version and System Specs
Zed: v0.179.2 (Zed) OS: macOS 15.3.2 Memory: 16 GiB Architecture: aarch64
This looks bad. I can reproduce this. Thank you for reporting. We will take look at this.