Warn about dead code
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
```
type someType = {
a : number,
b : string | null
}
//...
const ff = (data: someType): string => {
if (data.c === null) {
return 'field b is smpty';
}
return 'some value';
}
```
At this moment for flowtype this code is correct. Only that this code contains a logical error.
Flowtype could easily detect this error.
```
data.c === null
```
Left side is undefined (data.c is always undefined), right side is null. This condition always returns false.
So enough detect that the types specified for the operator compare are disjoint.
Another example:
```
type someStatusType = 'loading' | 'error' | 'ok';
const getLabel = (status: someStatusType): string => {
if (status === 'loading') {
return 'Loading';
}
if (status === 'error') {
return 'Error label';
}
if (status === 'complete') { //dead code
return 'Complete status';
}
return 'ok';
};
```
This dead code can be detected by this comparison :
```
status === 'complete'
```
This types are disjoint ( 'loading' | 'error' | ok' === 'complete' will always be false).
Contributor guide
Assessment
This issue has not been assessed yet.