Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EventEmitter: Enforce Function Type of Listener
Summary: Currently, `EventEmitter#addListener` defines the type (via TypeScript and Flow) of its second argument as a non-nullable function, and the implementation of `EventEmitter#emit` depends on this. However, not everyone may be using a static type system. We're seeing some people encounter a poor developer experience when they supply non-function values to `EventEmitter#addListener`, because the type mismatch is not surfaced as an error until `EventEmitter#emit` throws later on. This changes `EventEmitter#addListener` so that it throws when the second argument is not a function. This will make it easier for developers to identify the problematic call site because the stack trace will include the source of the non-function `listener` parameter. Changelog: [General][Changed] - `EventEmitter#addListener` now throws if the 2nd argument is not a function. Reviewed By: rshest Differential Revision: D43705465 fbshipit-source-id: 34ca91ac92862b31435bd12b7c9cb6da870a2a32
- Loading branch information