Disable the no-implicit-coercion
rule
#220
leroykorterink
started this conversation in
General
Replies: 2 comments
-
There are a lot of different ways to convert value types. Some of them might be hard to read and understand. Such as: const b = !!foo;
const b = ~foo.indexOf(".");
const n = +foo;
const n = 1 * foo;
const s = "" + foo;
foo += ``; Those can be replaced with the following code: const b = Boolean(foo);
const b = foo.indexOf(".") !== -1;
const n = Number(foo);
const n = Number(foo);
const s = String(foo);
foo = String(foo); Please see the documentation of the rule. |
Beta Was this translation helpful? Give feedback.
0 replies
-
In this case, it comes with better clarity; being explicit about what's happening, what's intended, without ambiguity (or chance for errors). Some examples where I like it being used (over <div isActive={Boolean(someValue && callSomeFunction(someValue))} />
<div>
{Boolean(child) && cloneElement(child as ReactElement, { ref: setBounds })}
</div>
const isMultiline = !isInline && Boolean(leftOne ?? rightOne);
<RowHeader ref={ref} onClick={onClick} $isClickable={Boolean(onRowClick)} {...props}> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There is a proposal to disable the
no-implicit-coercion
rule.Beta Was this translation helpful? Give feedback.
All reactions