facebook / facebook/flow

[Enhancement Proposal] Detect pointless conditionals.

Open
#4,889 1 comment 0 reactions 0 assignees View on GitHub
enhancement feature request
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

This is a feature request that will likely require some discussion and bikeshedding.

Often in Javascript we will check if a value is undefined and do something based on that. Sometimes, however, a value is never defined and the code inside the conditional becomes unreachable. Flow is in a unique position to detect this and warn about it.

Here's a minimal example to explain what I mean:

```js
/* @flow */

// empty exact object type
type Data = {|
foo: string
|}

const data: Data = {
foo: "hello there"
}

// unreachable if statement
if (data.bar) {
console.log('Launch the rockets!')
}

// unreachable default value
console.log(data.bar || 'Default Value')
```

Here flow has the ability to unequivocally know that the value will not be defined, but the conditional implies that the programmer expected the value to be defined at some point.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.