question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `no-unnecessary-type-casting`

See original GitHub issue

FAIL

if (Boolean(foo)) {}
if (!!foo) {}
foo(Boolean(bar) ? 1 : 2)
const foo = Boolean(bar);
if (foo) {}

Not sure about the last one, the example seems need fail, but this and this seems more readable with type-casting.

PASS

if (foo) {}
foo(bar ? 1 : 2)

Got the idea from #616 L167 L195, examples only shows Boolean type-casting, haven’t thought about other types.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
fiskercommented, May 3, 2020

I was going to implement this rule. But found this rule just before I get started.

The the built-in ESLint no-extra-boolean-cast rule.

Seems it’s doing the job I propose.

1reaction
fiskercommented, Apr 26, 2020

@papb I was trying to find some other case not about boolean, point is some people thought for..of only work on array.

Do you have any unnecessary type casting case in your mind?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule proposal: no unnecessary type casting #250 - GitHub
Casting to an assignable type is unnecessary. I would like to propose a rule that warns against it. For instance: let a: string...
Read more >
Test Procedure Manual for Voting Systems - State of Michigan
TEST PROCEDURES FOR NON-PARTISAN ELECTION WITH PROPOSALS. ... cast for an individual who is not a declared write-in candidate for the office and...
Read more >
Fact sheet CY 2023 Medicare Hospital Outpatient Prospective ...
In the CY 2023 OPPS/ASC proposed rule, CMS sought comments on the specific payment approach we might use for these services under the...
Read more >
HOW AN ISSUE BECOMES A BALLOT PROPOSAL
In the case of proposed constitutional amendments, signatures of registered voters must equal at least 10 percent of the number of votes cast...
Read more >
Robert's Rules of Order
Robert's Rules will help your group have better meetings, not ... Motion: To introduce a new piece of business or propose a decision...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found