简体   繁体   English

是否有禁止前缀类型断言语法的 TSLint 规则?

[英]Is there a TSLint rule that forbids the prefixed type assertion syntax?

Type assertion can be described in two ways:类型断言可以用两种方式描述:

  1. Prefixed前缀
<Foo>{ foo: 'bar' };
  1. Suffixed后缀
{ foo: 'bar' } as Foo;

Are there any TSLint rules that forbid the former and enforce the latter?是否有任何 TSLint 规则禁止前者并强制执行后者?

TSLint has a builtin rule for this very thing: no-angle-bracket-type-assertion TSLint 对此有一个内置规则: no-angle-bracket-type-assertion

To enable, add the rule to your tslint.json as follows要启用,请将规则添加到您的tslint.json中,如下所示

{
  "rules": {
    "no-angle-bracket-type-assertion": true
  }
}

There is an auto-fixer for the rule.该规则有一个自动修复程序。

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

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