Cannot test property exist on (A | (B & C)) type
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
If this is a bug, please try reproducing using https://flow.org/try/.
https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AUQE76z4DyARgFZYDGKoAvKAN6ICQAlgM4BqAhtOwAmALlCR+nLIgC+ydNlAARXil7kqtBszYA3fgFcsozinzsAdgHNQMuZhyKsq9tGWr1NOozdrKn0ABk2qyCTrwuxqYWlraIkPrmtOyw5qCWTh60ABQAlKIERKR+mgA+Siq+GnQsoKz4Tvr4qUygXHwCImISONI2snEJSSlpTo7O0JkoufmExJOgZWPhrhXzNXUNTcytPPxCouLQkqC9sdQpJqCwlFrpKJO5iOfml6Hj6rejYS4POYjskFAWWuFAAdG09oIGPRGIdJDlmLIAUC3st1ODdh1obDugimP0gA
```
type ErrorObject = {
isValid: false
}
type DataObject = {
value: string
}
type DetailDataObject = DataObject & {
detail: string
}
function getObject(): ErrorObject | DataObject {
return { isValid: false }
}
function getDetailObject(): ErrorObject | DetailDataObject {
return { isValid: false }
}
const obj = getObject()
const detailObj = getDetailObject()
if (obj.isValid === false) {} // ok
if (detailObj.isValid === false) {} // error
```
> 26: if (detailObj.isValid === false) {}
^ property `isValid`. Property cannot be accessed on any member of intersection type
What is the reason that I can check `obj.isValid` but not `detailObj.isValid`?
Or what is the best way to do type inheritance without using union type?
Contributor guide
Assessment
This issue has not been assessed yet.