facebook / facebook/flow

[Enhancement Proposal] Detect pointless conditionals.

Aperta
#4,889 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement feature request
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.