Yulian
Yulian

Reputation: 388

Is there a way to autocomplete class properties in TypeScript?

Is there a TypeScript/VSCode setting to autocomplete class properties when initializing classes? Similar to how Dart has insertArgumentPlaceholders (see question). I know TypeScript has completeFunctionCalls, but the functionality doesn't seem to extend to classes.

Currently I'm manually writing out every property, but it's pretty cumbersome for classes with many properties; requiring constant referencing back to the class definition.

For example:

class User {
  id: string;
  name: string;

  public constructor(init?: Partial<User>) {
    Object.assign(this, init);
  }
}

// Typing "const user = new User.." -> autocomplete/autofill to:
const user = new User({
  id: // <placeholder>,
  name: // <placeholder>,
});

Edit:

I'm aware about Copilot and similar extensions, they do not provide the functionality I'm asking about. My question is whether there is a built-in TypeScript feature to auto-suggest/auto-fill class properties. Copilot (and the like) suggest properties which usually don't even exist in classes, I'm curious whether there's a setting that mimics Dart's behavior.

Upvotes: 3

Views: 6994

Answers (2)

Philip Mutua
Philip Mutua

Reputation: 6891

If you are using VS Code you can use the JavaScript and TypeScript Nightly VS Code extension that is used to power JavaScript and TypeScript IntelliSense. The extension will be enabled globally therefore there will be no need of editing your VS Code settings.

Upvotes: 0

Gahan Vig
Gahan Vig

Reputation: 216

There is an awesome extension named Tabnine which supports almost every language and every IDE and editors. The AI of this extension is very strong. I recommend you to download it.

Tabnine official site

Tabnine extension on visual studio code site

Upvotes: 1

Related Questions