Combination of switch case and refinement of possibly undefined variable doesn't work
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
```js
//@flow
function getMaybe (): string|void {
return;
}
function doSomething (): string {
const target = getMaybe();
switch (true) {
case (target !== undefined):
return target;
default:
throw new Error('The target was undefined!');
}
}
```
The target within the case body should be refined that it cannot be undefined anymore. This also does not work when using `target instanceof SomethingElse` or `typeof target === 'notundefined'`.
https://flow.org/try/#0PTACDMBsHsHcCh7gK4DsDGAXAltVACAcwFNMBZAQwE8AjY-ACgEoAufAZ0wCdtVCAfAG7RsAE3wBvePnxdSyLqgDc8AL6IUGHHnyjoAZWgBbUgAtehRqw7cLk6fnR5O+TBS4lM+ALxFSlWmJmFRl2WGxMdFNGbmRiJnsZdAp2egY3D1J8AEJvXzRRYnBeYlFWBxk5TAUCDM8Q3SKKZEhMFgrXUy44fFRiWHwAUS5urgYAcgAVU3o6rNgU-AKiktFs8aYG9XUgA
Contributor guide
Assessment
This issue has not been assessed yet.