Search code examples
coding-styletypescript

TypeScript Coding Style Guide?


I love the Airbnb JavaScript Style Guide. Most of the rules also apply to TypeScript, but of course it doesn't cover specific TypeScript language features.

I have also found the Microsoft TypeScript Coding Guidelines but they are for the TypeScript project itself, not for projects that use TypeScript.

Finally I found the TypeScript Style Guide by Platypi but it's not as detailed as I'd like it to be. Is there another (official?) TypeScript Style Guide that I missed? Or are the two I listed the only ones that exist?


Solution

  • The TypeScript team doesn't issue an "official" style guide for other projects using TypeScript. The guidelines for working on the compiler itself are both too specific and not broad enough for general use; I would not use them as a baseline.

    Any JavaScript style guide that is up-to-date for ES6 is going to cover nearly all TypeScript constructs except for type annotations, so I would start with your favorite JS style and decide on what you want the rules for type annotations to be.

    TSLint is a good choice for enforcing style rules around types / type annotations.

    Update: TSLint is currently deprectated in favour of ESLint.