Перейти к содержимому

noUselessTypeConversion

Это содержимое пока не доступно на вашем языке.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noUselessTypeConversion": "error"
}
}
}
}

Disallow type conversions that do not change the type of an expression.

This rule reports common conversion patterns when the converted expression is already known to have the target base type (AKA primitive type).

invalid-string.ts
const text: string = "text";
String(text);
/invalid-string.ts:2:1 lint/nursery/noUselessTypeConversion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid calling `String()` on a string value.

1 │ const text: string = “text”;
> 2 │ String(text);
^^^^^^
3 │

This expression already evaluates to a string.

Remove the conversion and use the value directly.

Redundant conversions make it harder to see that the value already has the expected string type.

This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/9752 for more information or to report possible bugs.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

invalid-boolean.ts
const value: boolean = true;
!!value;
/invalid-boolean.ts:2:1 lint/nursery/noUselessTypeConversion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid applying `!!` to a boolean value.

1 │ const value: boolean = true;
> 2 │ !!value;
^^^^^^^
3 │

This expression already evaluates to a boolean.

This expression already evaluates to a boolean, so the double negation has no effect.

Redundant conversions make it harder to see that the value already has the expected boolean type.

This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/9752 for more information or to report possible bugs.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

invalid-assignment.ts
let str = "text";
str += "";
/invalid-assignment.ts:2:1 lint/nursery/noUselessTypeConversion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid appending an empty string to a string value.

1 │ let str = “text”;
> 2 │ str += "";
^^^^^^^^^
3 │

This expression already evaluates to a string.

This expression already evaluates to a string, so the empty string has no effect.

Redundant conversions make it harder to see that the value already has the expected string type.

This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/9752 for more information or to report possible bugs.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Genuine conversions are allowed.

String(1);
!!0;

Unboxing boxed values is allowed.

String(new String());