[bug][v0.69.0] Loss of refinement after accessing object property
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Basically if you check that an attribute of an object exists before making a refinement the refinement is lost.
I think this is unexpected as the attribute check shouldn't cause loss of typing on the parent object. I ran `flow suggest` on my actual codebase and the loss of refinement seems specifically tied to the attribute as the parent object was correctly limited by the `kind` check.
I have a bunch of repro cases in the [flow playground][playground] but the core of the problem is:
```javascript
function broken(o: TObject): void {
if (o.object) {
if (o.kind === "type1") {
needsType1(o.object) // this call doesn't typecheck
}
}
}
function works(o: TObject): void {
if (o.kind === "type1") {
needsType1(o.object)
}
}
```
I don't think this specific bug has been reported before but it seems (to varying degrees) related to:
- https://github.com/facebook/flow/issues/4353
- https://github.com/facebook/flow/issues/4328
- https://github.com/facebook/flow/issues/5312
[playground]: https://flow.org/try/#0PTAEAEDMBsHsHdQCgkBcCeAHApqAKnltgIygC8oA3kqKAG4CG0ArtgFygDOqATgJYA7AOYAaGvSasATBwHMAtgCNsPMQF8UGHPkI4AzOSrjGLdl16DRSDWiL4A8ooBW2AMapy4gD5VQAa0EAEw4AIi0SEJF-bHQObn5hKNhnN1QOAiJSDVofSn8g0PC9SOjY8wTRUGSXd3TdbANQG0hmAXc+WAFQAWxsQM564gAKWDrMgEoORVhYaGwGLupaHmxUZh4uyCZObGsUFrbUDq74WB4-ThH0xxrUSfpYPkCjWj5IUBGAOgCBZ4BCMgUMJEYrjF60bq9fqDL7VVLjcQaZqtdqdUDYAAemGgfFcfFQ0HQAHUzhcrg4Uu57nRHs8lqA3h9YN8guRAaBgThiCEwfTaD0+gNMrDKXdEXskMAAFRIA6orqKHiwPzYATkvA3eEcGlPcGMkagABkhqqnzhVPBr3eXx+-3ZnIaPMtEIF0OFzPNYohTXFGilwBQ0tlKKOaO4fGg0AAQkqVWrRhTbtTaXrrX9YKAvD502bRbzxMtVusBOLaOJ9czbaAAUCik6+ZDBTCPXnfUh-YGZXLQ11AthIIJ8dhCQA5WCoACqAkVytV6s1VO1KfpFdzSedq6rNY5dfz3v5UKFXJFSYLPtoSPbAclXZDx3RWJxeNQAGEABZuH5CGOz+PXPNLrqK7Wi264NpurKArWmT1meB5Nu6a7wme2Q+n617dverjrB0zCcISJLnJcCYagBDxAeWIF7hCKxrBspYMiBLK-NW9q7s6rpHiQJ7IRelFMkhFoNrRxZtsGhz3tssAvjhsB4QRpLEf+SaAXS-EGsapq2tRVoCVubEgrB+6Nm6x6gbxEKoUiQA
Contributor guide
Assessment
This issue has not been assessed yet.