Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alphabetically sort TypeScript interface keys

Is there a way to automatically sort TypeScript interface keys? I'm already using Prettier and VSCode so ideally the solution would be with those but I'm open to any solutions.

For example,

// before
interface MyInterface {
  foo: number;
  bar: number;
  baz: number;
}

// after sort
interface MyInterface {
  bar: number;
  baz: number;
  foo: number;
}
like image 989
J'e Avatar asked Dec 31 '22 05:12

J'e


1 Answers

Lots of plugins are available for VSCode. "Sort" by "Henrik Sjööh" works nicely.

After installing the plugin, highlight the interface and press alt+shift+s (option+shift+s on MacOS) and the interface will be reordered.

like image 81
J'e Avatar answered Jan 12 '23 08:01

J'e