简体   繁体   English

TypeScript编译器选项,用于实现超出严格模式的严格代码遵从

[英]TypeScript Compiler Options for strict code compliance beyond strict mode

We would like to configure TSC hopefully with a command line option to generate errors when developers declare class fields using implicit type expressions instead of explicit see code below. 当开发人员使用隐式类型表达式而不是显式的see代码声明类字段时,我们希望希望通过命令行选项配置TSC来生成错误。

class Appliance {
    //coding style we want to enforce:
    private _group:Group = new Group(); 

    //coding style we want to prevent by issuing error:
    private _group = new Group(); 

    //coding style we want to enforce as it does not rely only on
    //constructor parameters list for declaration 
    public assetTag:EquipmentTag; 

    public constructor(assetTag:AssetTag, 
        //coding style we want to prevent by issuing error if
        //no explicit declaration above constructor
        supplier:Company) {

        this.assetTag = assetTag; //coding style we want to enforce
    }

}

We use strict mode for TSC but it still allows for some casual coding style as shown. 我们对TSC使用严格模式,但是它仍然允许使用一些随意的编码样式,如图所示。

Is there any TSC option we can use to go beyond strict mode and enforce some coding style compliance? 我们可以使用任何TSC选项来超越严格模式并强制遵守某些编码样式吗?

Just as Titian suggested, code style is enforced by ts-lint https://palantir.github.io/tslint/ 正如Titian所建议的那样,代码样式由ts-lint https://palantir.github.io/tslint/强制执行

The Rule you are looking for: https://palantir.github.io/tslint/rules/typedef/ 您正在寻找的规则: https : //palantir.github.io/tslint/rules/typedef/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM