Skip to content

Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. #4

@huan

Description

@huan

When we start using typed-emitter, the event name is string literal instead of string, which will run into The way fromEvent checks if the first argument passed is an emitter or not is incorrect

Minimum Reproducible Code

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

import { fromEvent } from 'rxjs'

interface Events {
  foo: (n: number) => void
  bar: (s: string) => void
}

const TypedEmitter = EventEmitter as new () => TypedEventEmitter<Events>
const emitter = new TypedEmitter()

fromEvent(emitter, 'foo')
// Error: Type 'TypedEventEmitter<Events>' is not assignable to type 'JQueryStyleEventEmitter'.

Related Discussion

  1. rxjs fromEvent compatibility rxjs fromEvent compatibility andywer/typed-emitter#9
  2. Proposal: Statically typed fromEvent Proposal: Statically typed fromEvent ReactiveX/rxjs#4891
  3. typed-emitter compatibility typed-emitter compatibility devanshj/rxjs-from-emitter#4

To be fixed.

Update June 1, 2021

With RxJS 7.1, we can remove any but still get unknown.

It seems that the fromEvent still not be able to infer from on/off.

Update Nov 7, 2021

Have sent a PR for fixing this issue to RxJS:

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions