gpt4 book ai didi

typescript - TypeScript编译器选项,用于实现超出严格模式的严格代码合规性

转载 作者:行者123 更新时间:2023-12-02 10:57:40 24 4
gpt4 key购买 nike

当开发人员使用隐式类型表达式(而不是下面的显式代码)声明类字段时,我们希望希望通过命令行选项配置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
}

}

我们对TSC使用严格模式,但是它仍然允许使用一些随意的编码样式,如图所示。

我们是否可以使用任何TSC选项来超越严格模式并强制遵守某些编码风格?

最佳答案

正如Titian所建议的那样,代码样式由ts-lint https://palantir.github.io/tslint/强制执行

您正在寻找的规则:https://palantir.github.io/tslint/rules/typedef/

关于typescript - TypeScript编译器选项,用于实现超出严格模式的严格代码合规性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56760527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com