TypeScript 编码风格指南?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31990608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeScript Coding Style Guide?
提问by Johannes Fahrenkrug
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.
我喜欢Airbnb JavaScript 风格指南。大多数规则也适用于 TypeScript,但它当然不包括特定的 TypeScript 语言功能。
I have also found the Microsoft TypeScript Coding Guidelinesbut they are for the TypeScript project itself, not for projects that useTypeScript.
我还找到了Microsoft TypeScript 编码指南,但它们适用于 TypeScript 项目本身,而不适用于使用TypeScript 的项目。
Finally I found the TypeScript Style Guide by Platypibut 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?
最后我找到了Platypi的TypeScript 风格指南,但它没有我想要的那么详细。我错过了另一个(官方?)TypeScript 样式指南吗?或者我列出的两个是唯一存在的?
采纳答案by Ryan Cavanaugh
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.
TypeScript 团队不会为其他使用 TypeScript 的项目发布“官方”风格指南。编译器本身的工作指南既过于具体,又不足以广泛用于一般用途;我不会将它们用作基线。
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.
任何适用于 ES6 的最新 JavaScript 样式指南都将涵盖除类型注释之外的几乎所有 TypeScript 构造,因此我将从您最喜欢的 JS 样式开始,并决定您希望类型注释的规则是什么。
TSLintis a good choice for enforcing style rules around types / type annotations.
TSLint是围绕类型/类型注释强制执行样式规则的不错选择。
回答by david
Maybe this is a bit late, but I stumbled upon https://github.com/excelmicro/typescriptwhich also provides a bit more detailed tslint.json in the linters folder ... it is also based on the airbnb/javascript styleguide ...
也许这有点晚了,但我偶然发现了https://github.com/excelmicro/typescript,它也在 linters 文件夹中提供了更详细的 tslint.json ......它也基于 airbnb/javascript styleguide 。 ..
Yet another Styleguide (which we use for angular 1 development with TypeScript) is https://angular.io/guide/styleguide
另一个样式指南(我们使用 TypeScript 进行 angular 1 开发)是https://angular.io/guide/styleguide