I'm trying to trick test coverage calculation to work with while true loops. The coverage tools I am using consider test coverage to be lacking due to the while ending case is never executed. This is obviously a bug in the coverage calculation. However, I am trying to invent something that works until the coverage calculation gets fixed upstream, or at least until a suitable ignore comment is implemented.

The problematic code looks as follows. This works fine and tests work fine. However, I get the missing code coverage due to the while loop never exiting.

```
function* greetings1(): Generator<string, never, undefined> {
  while(true) {
    yield 'hello'
  }
}

```

I explored the idea of creating a constant `TRUE` that would let specially crafted tests to exit the loops by mocking the constant `TRUE` and replacing it with a `false` value that exists the loop. However, this gives me a type error `A function returning 'never' cannot have a reachable end point. ts(2534)`.

```
const TRUE: true = true
function* greetings2(): Generator<string, never, undefined> {
  while(TRUE) {
    yield 'hello'
  }
}

```

Is it possible to add an escape hatch for exiting the while true loop without having to sacrifice the types and result to casting the entire function body? I would be fine doing a tricky cast with the constant `TRUE` if needed.

I also tried some tricks using `break`. However, the coverage tool considers the use of `break` to be different from the condition becoming false, so that does not entirely solve my problem. Is there is a solution, it probably needs to be based making the while loop end naturally.

I posted a related question about a specific code coverage tool one year ago. See [Istanbul code coverage : Ignore else branch of a while true loop](https://stackoverflow.com/questions/69242625)