alphabetically sort TypeScript interface keys alphabetically sort TypeScript interface keys typescript typescript

alphabetically sort TypeScript interface keys


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.


A perhaps better approach would be to enforce such a thing, especially if you are working on a team. Linters actually have support for this and it's called object-sort-keys for tslint and sort-keys for eslint. They also come with auto fixes within VS Code, so if you activate this rule on any linter, you can automatically fix the ordering of the keys. (You could even do this on Save -> fix all linting issues on save).

https://eslint.org/docs/rules/sort-keyshttps://palantir.github.io/tslint/rules/object-literal-sort-keys/ (careful, tslint will be deprecated in favor of eslint soon)


To sort object keys alphabetically, I am using the extension Sort JS Object.