andywer / andywer/typed-emitter

Extending EventEmitter and implementing TypedEventEmitter is broken

Aperta
#43 5 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
285
Fork
29
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hi,

The following example works with typed-emitter v1, but breaks with v2.

```typescript
import { EventEmitter } from 'events';
import TypedEmitter from 'typed-emitter';

type TestEvents = {
foo: () => void;
};

export class ITestEventEmitter extends (EventEmitter as new () => TypedEmitter) { }

export abstract class TestClass extends EventEmitter implements ITestEventEmitter {
}
```

Error message:
```
Class 'TestClass' incorrectly implements class 'ITestEventEmitter'. Did you mean to extend 'ITestEventEmitter' and inherit its members as a subclass?
The types returned by 'rawListeners(...)' are incompatible between these types.
Type 'Function[]' is not assignable to type 'TestEvents[E][]'.
Type 'Function' is not assignable to type 'TestEvents[E]'.
Type 'Function' is not assignable to type '() => void'.
Type 'Function' provides no match for the signature '(): void'.ts(2720)
```

My use-case is a class that extends another class, which is an `EventEmitter`, but needs to also implement typed events.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.