opened
laverdet
username_0
<!--
If you have a problem with a specific rule, please begin your issue title with [rulename] to make it easier to search for.
I.e. "[no-unused-vars] False positive when fooing the bar"

Please don't ignore this template.

If you ignore it, we're just going to respond asking you to fill it out, which wastes everyone's time.
The more relevant information you can include, the faster we can find the issue and fix it without asking you for more info.
-->

<!--
Are you opening an issue because the rule you're trying to use is not found?
🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨
1) Check the releases log: https://github.com/typescript-eslint/typescript-eslint/releases
    -  If the rule isn't listed there, then chances are it hasn't been released to the main npm tag yet.
2) Try installing the `canary` tag: `npm i @typescript-eslint/eslint-plugin@canary`.
    - The canary tag is built for every commit to master, so it contains the bleeding edge build.
3) If ESLint still can't find the rule, then consider reporting an issue.
-->

<!--
Make sure you read through our FAQ before posting.
https://github.com/typescript-eslint/typescript-eslint/blob/issue-template-update/docs/getting-started/linting/FAQ.md
-->

<!--
Include a ***minimal*** reproduction case.
The more irrelevant code/config you give, the harder it is for us to investigate.
-->

```JSON
{
  "rules": {
    "@typescript-eslint/no-unnecessary-condition": "warn"
  }
}
```

```ts
class Foo {
	flag = false;
	*run() {
		if (this.flag) return 1;
		yield;
		if (this.flag) return 2;
		return 3;
	}
}
```

**Expected Result**
I wouldn't expect an error here because control is yielded back to anyone after the yield.

**Actual Result**
6:7  warning  Unnecessary conditional, value is always falsy  @typescript-eslint/no-unnecessary-condition


**Versions**

| package                            | version |
| ---------------------------------- | ------- |
| `@typescript-eslint/eslint-plugin` | `^2.25.0` |
| `@typescript-eslint/parser`        | `^2.25.0` |
| `TypeScript`                       | `3.8.3` |
| `ESLint`                           | `6.8.0` |
| `node`                             | `13.11.0` |
| `npm`                              | `6.13.7` |
[no-unnecessary-condition] misfires after yield in generator
issue
created
bradzacher
username_1
Typescript does not do control-flow analysis on the fact that the yield returns to the caller, and the caller could mutate the class property.

The rule just reads the types provided by typescript, and as far as typescript is concerned, the type of the variable has been narrowed to `false`.

Feel free to raise this as a feature request in the typescript repo.
comment
closed
bradzacher
username_1
issue