Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-4137

Type assertions should use "as"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Use "as" type assertion here instead.
    • Highlighting:
      Hide

      <foo>

      Show
      <foo>
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way recommended
    • Covered Languages:
      TypeScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources
    • TSLint:
      no-angle-bracket-type-assertion

      Description

      Type assertion can be done in two ways: with as MyType or with <MyType>. But since there is an ambiguity in the latter when using JSX and there is no ambiguity in the former, as is preferred.

      Noncompliant Code Example

      var foo = <any>"foo";  // Noncompliant
      

      Compliant Solution

      var foo = "foo" as any;
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: