react-native
react-native copied to clipboard
Fix RCTDeviceEventEmitter export type
Summary:
In a recent update of React Native, we noticed that the export of RCTDeviceEventEmitter types is wrong.
After the update, the export in .d.ts
has been changed to export const
.
But in the .js
file the export still with export default
.
Fixes #37358
Changelog:
[GENERAL][FIXED] - Fix RCTDeviceEventEmitter export type
Test Plan:
Let’s add tests to the typetests directory to verify what you are trying to fix.
I think as-is this would say you can “import {DeviceEventEmitterStatic} from ‘react-native’” which isn’t correct.
@NickGerleman I do that because of index.tsx is importing like this:
https://github.com/facebook/react-native/blob/65b792ce0bc5aaf9e30d5d0506a7af97e2a90a97/packages/react-native/types/typetests/index.tsx#L37-L38
And used here:
https://github.com/facebook/react-native/blob/65b792ce0bc5aaf9e30d5d0506a7af97e2a90a97/packages/react-native/types/typetests/index.tsx#L1055-L1058
Can I just remove the type that point to DeviceEventEmitterStatic
directly?
// DeviceEventEmitterStatic
- const deviceEventEmitterStatic: DeviceEventEmitterStatic = DeviceEventEmitter;
+ const deviceEventEmitterStatic = DeviceEventEmitter;
deviceEventEmitterStatic.addListener('keyboardWillShow', data => true);
deviceEventEmitterStatic.addListener('keyboardWillShow', data => true, {});
Or:
// DeviceEventEmitterStatic
- const deviceEventEmitterStatic: DeviceEventEmitterStatic = DeviceEventEmitter;
- deviceEventEmitterStatic.addListener('keyboardWillShow', data => true);
- deviceEventEmitterStatic.addListener('keyboardWillShow', data => true, {});
+ DeviceEventEmitter.addListener('keyboardWillShow', data => true);
+ DeviceEventEmitter.addListener('keyboardWillShow', data => true, {});
Platform | Engine | Arch | Size (bytes) | Diff |
---|---|---|---|---|
android | hermes | arm64-v8a | 8,723,623 | -3,038 |
android | hermes | armeabi-v7a | 8,034,457 | -3,055 |
android | hermes | x86 | 9,210,697 | -3,046 |
android | hermes | x86_64 | 9,065,035 | -2,949 |
android | jsc | arm64-v8a | 9,288,247 | -3,166 |
android | jsc | armeabi-v7a | 8,476,513 | -3,170 |
android | jsc | x86 | 9,346,718 | -3,156 |
android | jsc | x86_64 | 9,604,652 | -3,070 |
Base commit: 65b792ce0bc5aaf9e30d5d0506a7af97e2a90a97 Branch: main
It would be better if the naming of the TypeScript types aligned with what's in the main JS files (which is IEventEmitter
).
It still seems like the typescript exports do not match the actual module (and so the typetests may be testing the wrong thing!). RCTDeviceEventEmitter
only exports a default EventEmitter instance, with the 'IEventEmitter class' being in vendor/emitter/EventEmitter
.
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This PR was closed because it has been stalled for 7 days with no activity.