Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

(strict-boolean-expressions) while (true) { ... } #2385

Closed
benny-medflyt opened this issue Mar 22, 2017 · 1 comment
Closed

(strict-boolean-expressions) while (true) { ... } #2385

benny-medflyt opened this issue Mar 22, 2017 · 1 comment

Comments

@benny-medflyt
Copy link

Some algorithms are best naturally coded using an "infinite" loop of the style:

while (true) {
   ...
   if (someCondition) {
      break;
   }
   ...
}

but the strict-boolean-expressions tslint rule does not like this, giving the message:

This type is not allowed in the 'while' condition because it is always truthy. Only booleans are allowed.

This message is sensible for "if" statements, and also for "while" statements such as while (x !== null) (where "x" is known to be non-null).

But I would argue that using a literal "true", as in while (true) should not be an error, and is an intentional programming construct, and the strict-boolean-expressions rule should not report it as an error.

Thank you

@jupl
Copy link

jupl commented Mar 31, 2017

I use for(;;) { ... } which eliminates the conditional.

EDIT: In fact, I learned this originally when I use ESLint because of their documentation. Probably a separate issue, but TSLint could benefit from examples in the documentation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants