Flow reports implicitly returned undefined even when not possible
- Lingua principale
- Rust
- Stelle
- 22.3k
- Fork
- 1.9k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I keep running into more complex version of [this example code](https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVBjOA7AzgFzAFMAPAWwAcYwBeMACgEtsKBXfALm1bICMiATgEouPfgNoA+MAG9UYMAgAWjGEQb4BrIkNnyFYXAkb4MShszb5dcgwYwBDXOoAMHfXYUCi+VgOxgluweBgAmRFAOrDCcIXbevv5gLiEAvvrpqUA) fairly often:
```js
/* @flow */
const exmpl = (input:number):number => {
while (true) {
switch (input) {
case 0:
return input
default:
return 0
}
}
}
```
Which flow fails to type check with a following error:
```
3: const exmpl = (input:number):number => {
^ number. This type is incompatible with an implicitly-returned undefined.
```
Most likely flow is failing to infer that `while` block will ever be executed. I am not sure how difficult would it be make flow type check this code, but either way it would really help if flow provided a hint on why it assumes implicitly returned `undefined` something, telling user that while block may never run would greatly improve usability.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.