All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S6564.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

TypeScript provides the type mechanism to create a type alias, that is, a new name to refer to an existing type. It is a nice feature to improve code readability and can be used as documentation. However, aliasing a primitive type, another alias or everyday types like any or unknown is useless and goes against the idea of readable code. As a result, a reader needs to go through the mental exercise of remembering the underlying type behind the alias and loses track of the code’s primary purpose.

Common types come with relevant names and should be used as they are.

How to fix it

The type alias should be removed, and all the occurrences of the alias should be replaced with the type it referred to.

Code examples

Noncompliant code example

type MyString  = string;
type MyBoolean = boolean;

function isPalindrom(s: MyString): MyBoolean {
    return s === s.split('').reverse().join('');
}

Compliant solution

function isPalindrom(s: string): boolean {
    return s === s.split('').reverse().join('');
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy