bvaughn / react-devtools-experimental

Experimental rewrite of the React DevTools extension
https://react-devtools-experimental.now.sh
MIT License
965 stars 55 forks source link

Add Flow types to Bridge messages #309

Closed bvaughn closed 5 years ago

bvaughn commented 5 years ago

It is currently too easy to mismatch types between what we send through the Bridge and what we listen for (addListener). We should harden these types by specifically enumerating all possible combinations.

bvaughn commented 5 years ago

Looks like the current set of bridge message we are sending is:

bvaughn commented 5 years ago

I think we could improve our current Flow definition for the EventEmitter type to be one that requires explicit event parameters:

declare module "events" {
  declare class EventEmitter<Events: Object> {
    addListener<Event: $Keys<Events>>(
      event: Event,
      listener: (...$ElementType<Events, Event>) => any
    ): void;
    emit: <Event: $Keys<Events>>(
      event: Event,
      ...$ElementType<Events, Event>
    ) => void;
    removeListener(event: $Keys<Events>, listener: Function): void;
    removeAllListeners(event?: $Keys<Events>): void;
  }

  declare export default typeof EventEmitter;
}
bvaughn commented 5 years ago

ea03ddd