facebook / facebook/flow

In v0.54, intersection of objects with properties of the same name seems to behave strangely

Open
#4,815 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

```javascript
function _onClearButtonFocus(
e: SyntheticFocusEvent & { relatedTarget: HTMLElement }
) {
// prevent the focus on the clear button
if (e.relatedTarget) {
e.relatedTarget.focus();
} else {
e.currentTarget.blur();
}
}
```

Error:
```
6: e.relatedTarget.focus();
^ property `focus`. Property not found in
6: e.relatedTarget.focus();
^ EventTarget
```

[Here is a Try](https://flow.org/try/#0PTAEGkHkCgDMFcB2BjALgSwPaNKA+tgMIA2ApgIYBOAQvKqtgGKbLwDOAFNLqQFygBlAJ6JUAC1IZkzVmwCiAN1KiAPAAkAKgFkAMnLIBbZagB8oAGSgA3qEqli5VKQAmGqgHNJ-Tbv2kjoqAAvtAAlNbcoCCgAA52SoHipKCwLOyg2KBJoMhkVKAARnQMiJHosKAcpAB0dg5Orh6S4VaRPLX2ji5ulJ6o1amyHKEA3JFBoPZsya247ayUdqI9fdUFxPCUw2O4ISHQ0QDumJQA1mxwSGhYOPhEeTTFTGmckXyCIklSisbq2nqGYxmSw2OpdRq9LygHwA-zGYJhCK4aJxUgJVBZCQpF4ZHDZXIUSiFJ6lXDlSo1MENFbNJFzSmdalNfqDdjbcaTYjTOnzTZLVA0-rrTbs3bQfbRSDgaCoIQxZKC0AAXlAP2WzIs0P+fgCqDGCBQGEyTjYqA4qGZ-EFLUiFshLJe7JCQA).

The problem I see is that `SyntheticFocusEvent` is defined with a `relatedTarget: EventTarget` property. But this shouldn't be a problem !

It looks like that a "direct" intersection works fine (see last example on the try).

A possible fix would be to define SyntheticFocusEvent to have 2 type parameters: one for `currentTarget` and one for `relatedTarget`. But I feel like there is a deeper bug here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.