noUselessTypeConversion
このコンテンツはまだ日本語訳がありません。
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noUselessTypeConversion - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUselessTypeConversion": "error" } } }}Description
Section titled “Description”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).
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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.
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.
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());Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.