Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EventEmitter ts definition file #36462

Conversation

helenaford
Copy link
Contributor

@helenaford helenaford commented Mar 13, 2023

Summary

There's an error in the d.ts file for EventEmitter which causes the following error:

This expression is not constructable.
  Type 'typeof import(".../vendor/emitter/EventEmitter")' has no construct signatures.
const emitter = new EventEmitter();
                      ~~~~~~~~~~~~

See

export default class EventEmitter<TEventToArgsMap: {...}>

Changelog

Test Plan

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 13, 2023
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,519,172 +0
android hermes armeabi-v7a 7,834,700 +0
android hermes x86 8,999,506 +0
android hermes x86_64 8,854,758 +0
android jsc arm64-v8a 9,142,474 +0
android jsc armeabi-v7a 8,333,842 +0
android jsc x86 9,197,229 +0
android jsc x86_64 9,455,335 +0

Base commit: 803bb16
Branch: main

Copy link
Contributor

@NickGerleman NickGerleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #36109 it seemed like we shouldn't be exposing EventEmitter at all, since we do not export it as part of our entrypoint for public APIs.

Are you seeing this error when trying to import this as a source file from RN directly by chance?

@helenaford
Copy link
Contributor Author

helenaford commented Mar 14, 2023

@NickGerleman ah interesting. We use it in notifee. not sure what the alternative would be to use 🙁

However, either way, the ts definition file is wrong, even if it's for internal use only. This change doesn't change how EventEmitter is exposed.

@helenaford helenaford requested a review from NickGerleman March 14, 2023 17:37
Copy link
Contributor

@NickGerleman NickGerleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is an improvement that the type lines up.

For more context, many of the existing types do not line up internal to the public export, as an artifact of the current types being split from a flat file.

I.e. most of the files have it describing the interface as exported by RN, directly re-exported, vs the type being correct internally, and the re-exporting done at a higher layer. But that’s more an unfortunate historical artifact instead of the ideal.

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 16, 2023
@facebook-github-bot
Copy link
Contributor

@javache merged this pull request in 4acef8e.

OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
There's an error in the `d.ts` file for EventEmitter which causes the following error:

```
This expression is not constructable.
  Type 'typeof import(".../vendor/emitter/EventEmitter")' has no construct signatures.
const emitter = new EventEmitter();
                      ~~~~~~~~~~~~
```

See https://github.com/facebook/react-native/blob/dce9d8d5de381fe53760ddda0d6cbbdfb5be00e4/Libraries/vendor/emitter/EventEmitter.js#L63

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[GENERAL] [FIXED] -Fixes an issue with the EventEmitter type definition file

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Pull Request resolved: facebook#36462

Reviewed By: cipolleschi

Differential Revision: D44130846

Pulled By: javache

fbshipit-source-id: 64cecdf55e58b99b243392811226e5095d5dc006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants