Skip to content

typed-emitter compatibility #4

@huan

Description

@huan

Hi @devanshj ,

Thank you very much for your great module! I run into the same issue as you before today. (see: wechaty/redux#4)

After performed my google-fu, I found your issue ReactiveX/rxjs#4891, and here, where I believe it will be my final destination. ;^)

I'm using the TypedEmitter which is really nice to type my emitter classes, when I use fromEmitter() with the typedEmitter, I found that if we have more than one event, unfortunately we will get an unknown typing with the returned Observable, which I believe it is a bug.

Minimum Reproducible Code

import { EventEmitter }   from 'events'
import TypedEventEmitter  from 'typed-emitter'

import { fromEmitter } from 'rxjs-from-emitter'

interface Events {
  foo: (n: number) => void
  bar: (s: string) => void
}
const TypedEmitter = EventEmitter as new () => TypedEventEmitter<Events>

const emitter = new TypedEmitter()

const $ = fromEmitter(emitter).event('foo')
// const $: Observable<unknown>

If we remove bar in the Events interface, then the $ will be able to be inference right: const $: Observable<number>

I tried to dive into your code to fix it, however, the Typing code is more than I expected.

Would really appreciate it if we can get our fromEmitter works with typedEmitter, thank you for your time for my issue, and looking forward to seeing your reply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions