typed-emitter
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -1,2 +0,2 @@ | ||
type EventMap = { | ||
export type EventMap = { | ||
[key: string]: (...args: any[]) => void | ||
@@ -11,3 +11,3 @@ } | ||
* ```typescript | ||
* interface MyEvents { | ||
* type MyEvents = { | ||
* error: (error: Error) => void; | ||
@@ -42,10 +42,4 @@ * message: (from: string, content: string) => void; | ||
setMaxListeners (maxListeners: number): this | ||
/** | ||
* required by `FromEvent` | ||
* @see https://github.com/devanshj/rxjs-from-emitter/issues/4#issuecomment-665104646 | ||
*/ | ||
__events: Events | ||
} | ||
export default TypedEventEmitter |
{ | ||
"name": "typed-emitter", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -18,3 +18,6 @@ "description": "Strictly typed event emitter interface for TypeScript 3.", | ||
"rxjs": "*" | ||
}, | ||
"devDependencies": { | ||
"rxjs": "^7.5.2" | ||
} | ||
} |
@@ -28,3 +28,3 @@ # Typed-Emitter | ||
// Key: Event name; Value: Listener function signature | ||
interface MessageEvents { | ||
type MessageEvents = { | ||
error: (error: Error) => void, | ||
@@ -77,3 +77,3 @@ message: (body: string, from: string) => void | ||
import { fromEvent as rxFromEvent } from "rxjs" | ||
import { FromEvent } from "typed-emitter/rxjs" | ||
import { default as TypedEmitter, FromEvent } from "typed-emitter/rxjs" | ||
@@ -80,0 +80,0 @@ // The `Observable` typing can be correctly inferenced |
/** | ||
* devanshj/rxjs-from-emitter#4 - typed-emitter compatibility | ||
* | ||
* | ||
* @see https://github.com/devanshj/rxjs-from-emitter/issues/4#issuecomment-665104646 | ||
*/ | ||
/* eslint-disable no-use-before-define */ | ||
import { | ||
fromEvent as rxFromEvent, | ||
import { | ||
fromEvent as rxFromEvent, | ||
Observable, | ||
} from 'rxjs' | ||
import type TypedEventEmitter from '../index' | ||
import type { default as BaseTypedEmitter, EventMap } from '../index' | ||
@@ -19,8 +19,18 @@ type ObservedValue<A extends unknown[]> = | ||
interface FromTypedEvent { | ||
< Emitter extends TypedEventEmitter<any> | ||
< Emitter extends TypedEmitter<any> | ||
, EventName extends keyof Events | ||
, Events = Emitter extends TypedEventEmitter<infer T> ? T : never | ||
>(emitter: Emitter, event: EventName): Observable<ObservedValue<Events[EventName] extends (...args: infer A) => any ? A : never>> | ||
, Events = Emitter extends TypedEmitter<infer T> ? T : never | ||
>(emitter: Emitter, event: EventName): Observable<ObservedValue<Events[EventName] extends (...args: infer A) => any ? A : never>> | ||
} | ||
export type FromEvent = FromTypedEvent & typeof rxFromEvent | ||
interface TypedEmitter<Events extends EventMap> extends BaseTypedEmitter<Events> { | ||
/** | ||
* required by `FromEvent` | ||
* @see https://github.com/devanshj/rxjs-from-emitter/issues/4#issuecomment-665104646 | ||
*/ | ||
__events: Events | ||
} | ||
export default TypedEmitter |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7341
70
1