facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.07k stars 1.85k forks source link

nativeEvent in SyntheticTouchEvent may not have correct properties #4564

Open mikaello opened 7 years ago

mikaello commented 7 years ago

When using PanResponder in react-native, an event of type synthetic touch event is made available as a variable. This has a property nativeEvent with the following properties identifier, locationX, locationY, pageX, pageY, target, timestamp, touches. SyntheticTouchEvent in flow does have a property nativeEvent (by inheritance), but this points to Event which does not contain all the properties mentioned in the PanResponder-docs. The PanResponder-docs does not seem in sync with the types flow have defined.

When looking at the RN-code for places where a similar event is used, it is made an ad hoc solution:

type EventLike {
  nativeEvent: Object,
}

// ...
findViewForTouchEvent = (e: EventLike) => {
    var {locationX, locationY} = e.nativeEvent.touches[0];
    // ...
}

Does this mean that the synthetic touch event mentioned in PanResponder-docs (or Gesture Responder System-docs) is not the same as SyntheticTouchEvent mentioned in flow? Or is one of them not correct/up to date?

See example usage in flow try.

femiveys commented 6 years ago

Any reaction on this? I face the same issue

EvHaus commented 6 years ago

This is actually not limited to just SyntheticTouchEvent. Right now all Synthetic*Event types specify their nativeEvent key as a plain Event. It would be more accurate to make those events more specific, ie:

I've opened a Pull Request to address the issue: https://github.com/facebook/flow/pull/5303