react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Fix RCTDeviceEventEmitter export type

Open douglasjunior opened this issue 1 year ago • 5 comments

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:

douglasjunior avatar May 10 '23 17:05 douglasjunior

Let’s add tests to the typetests directory to verify what you are trying to fix.

NickGerleman avatar May 11 '23 00:05 NickGerleman

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, {});

douglasjunior avatar May 11 '23 11:05 douglasjunior

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

analysis-bot avatar May 11 '23 11:05 analysis-bot

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.

javache avatar Aug 22 '23 09:08 javache

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.

github-actions[bot] avatar Feb 19 '24 05:02 github-actions[bot]

This PR was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Feb 26 '24 05:02 github-actions[bot]