Type refinement isn't detected when value is assigned to a variable first
Open
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
An example speaks louder than words:
```js
type Err = {
status: 'Err',
msg: string,
}
type Ok = {
status: 'Ok',
data: number,
}
type Result = Err | Ok
const result: Result = JSON.parse('{"status": "Ok", "data": 5}')
// this works
if (result.status === 'Ok') {
console.log(result.data * 2)
}
// But this doesn't work!
const status = result.status
if (status === 'Ok') {
console.log(result.data * 2)
}
```
Contributor guide
Assessment
This issue has not been assessed yet.