Search code examples
typescripttslint

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?


Solution

  • TSLint has a builtin rule for this very thing: no-angle-bracket-type-assertion

    To enable, add the rule to your tslint.json as follows

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

    There is an auto-fixer for the rule.