TypeScript Coding Style Guide?

Coding StyleTypescript

Coding Style Problem Overview


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?

Coding Style Solutions


Solution 1 - Coding Style

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.

Solution 2 - Coding Style

Maybe this is a bit late, but I stumbled upon https://github.com/excelmicro/typescript which also provides a bit more detailed tslint.json in the linters folder ... it is also based on the airbnb/javascript styleguide ...

Yet another Styleguide (which we use for angular 1 development with TypeScript) is https://angular.io/guide/styleguide

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohannes FahrenkrugView Question on Stackoverflow
Solution 1 - Coding StyleRyan CavanaughView Answer on Stackoverflow
Solution 2 - Coding StyledavidView Answer on Stackoverflow