Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode intellisense auto generate missing TypeScript type properties on defined object

VSCode's intellisense has an option for pulling in the required interface members. Can it also do this for TypeScript Types?

For example if I have an exported type:

export type Button = {
  id: string;
  text: string;
  color?: ColorOptions;
  icon?: string;
  tooltip?: Tooltip;
};

When I create a new object:

const button: Button = {
   // No Code Actions.
}

I don't have any code actions to fill in the required properties.

I would honestly like it to also have an option to pull in optional props as well. I know I can peek + copy + paste, but then I have to reformat, as the syntax for defining and using a type is not the same.

Does this functionality exist?

like image 475
CAlex Avatar asked Jul 15 '19 16:07

CAlex


2 Answers

Update: this is going to be part of Typescript in a future release, so you won't need to install this extension anymoire. https://github.com/microsoft/TypeScript/pull/44576


I've made a typescript language server plugin and vscode extension called TS Quickfixes that adds this functionality. It's very basic and doesn't support many cases yet, so please raise an issue if your use case isn't covered: https://github.com/tamj0rd2/ts-quickfixes

Extension: https://marketplace.visualstudio.com/items?itemName=tamj0rd2.ts-quickfixes-extension

Language server plugin: https://www.npmjs.com/package/ts-quickfixes-plugin

like image 124
tamj0rd2 Avatar answered Sep 22 '22 08:09

tamj0rd2


As of VS Code 1.36, that quick fix is not available.

The feature request is being tracked here

like image 39
Matt Bierner Avatar answered Sep 22 '22 08:09

Matt Bierner