Repository navigation
[Strict TS API] NativeSyntheticEvent doesn't match BaseSyntheticEvent #57910
Description
Activity
The reason this only shows up on 0.87 is that the two type surfaces disagree with each other.
The hand-written
Libraries/Types/CoreEventTypes.d.tshas:export interface NativeSyntheticEvent<T> extends React.BaseSyntheticEvent< T, HostInstance, HostInstance > {}
so on the legacy types these were assignable to
BaseSyntheticEvent. The Strict API types are generated from the Flow source instead, andCoreEventTypes.jsdeclaresbubbles: ?boolean,cancelable: ?boolean,eventPhase: ?number,isTrusted: ?booleanandtype: ?string.For what it's worth the Flow side looks like the accurate one. Those fields are copied straight off the native event payload. A
nullentry inSyntheticEvent.Interfacemeans "copy verbatim", and the constructor does:(targetInst = dispatchConfig[propName]) ? (this[propName] = targetInst(nativeEvent)) : "target" === propName ? (this.target = nativeEventTarget) : (this[propName] = nativeEvent[propName]);
bubbles,cancelable,eventPhase,isTrustedandtypeare allnullentries in that Interface, so their runtime value is whatever the native payload carried, and native payloads generally don't include DOM event metadata. Soundefinedis a real case here, not a typing artifact.If that's right, then the
.d.tswas the inaccurate surface and tightening the generated types to matchBaseSyntheticEventwould paper over a genuine runtime value. Probably worth someone confirming which of the two is the intended contract before anything changes.@aravi365 how a
typeprop can beundefined?@retyui it's undefined whenever the native payload doesn't carry a
typekey.typeis one of thenullentries inSyntheticEvent.Interface, and for those the constructor copies the field straight off the native event (ReactFabric-dev.js, around line 810):: (this[propName] = nativeEvent[propName])
The event name never ends up there. Fabric's
dispatchEvent(target, topLevelType, nativeEventParam)gets it as the separatetopLevelTypeargument and nothing writes it back ontonativeEvent.type. The only subclass,ResponderSyntheticEvent, just addstouchHistory.So unless a particular native event puts
typein its payload, you getundefined. Aconsole.log(event.type)in anonSubmitEditinghandler should show it. That's why Flow has it as?string.Reacted by Davyd NRB

Description
My team uses unified codebase that share web and native code, so that is why a
BaseSyntheticEventevent was used here.this issue doesn't not exist in prev. RN versions
Steps to reproduce
see above
React Native Version
0.87.0
Affected Platforms
Runtime - Android, Runtime - iOS
Output of
npx @react-native-community/cli infoStacktrace or Logs
MANDATORY Reproducer
https://github.com/retyui/repo_with_virus_to_steal_corporate_data_so_you_get_fired_and_spend_the_rest_of_your_life_in_prison
Screenshots and Videos
...