diff --git a/README.md b/README.md index 70c1fd4..770191e 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ This can be fixed by the following code, by replacing the `fromEvent` type with ```ts import { fromEvent as rxFromEvent } from "rxjs" -import { FromEvent } from "typed-emitter/rxjs" +import { default as TypedEmitter, FromEvent } from "typed-emitter/rxjs" // The `Observable` typing can be correctly inferenced const fromEvent = rxFromEvent as FromEvent diff --git a/index.d.ts b/index.d.ts index 7f6458f..d18212c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -type EventMap = { +export type EventMap = { [key: string]: (...args: any[]) => void } @@ -38,12 +38,6 @@ interface TypedEventEmitter { getMaxListeners (): number setMaxListeners (maxListeners: number): this - - /** - * required by `FromEvent` - * @see https://github.com/devanshj/rxjs-from-emitter/issues/4#issuecomment-665104646 - */ - __events: Events } export default TypedEventEmitter diff --git a/package-lock.json b/package-lock.json index ca7dcc3..1dada0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,51 @@ { "name": "typed-emitter", "version": "2.0.0", - "lockfileVersion": 1 + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "typed-emitter", + "version": "2.0.0", + "license": "MIT", + "devDependencies": { + "rxjs": "^7.5.2" + }, + "optionalDependencies": { + "rxjs": "*" + } + }, + "node_modules/rxjs": { + "version": "7.5.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.2.tgz", + "integrity": "sha512-PwDt186XaL3QN5qXj/H9DGyHhP3/RYYgZZwqBv9Tv8rsAaiwFH1IsJJlcgD37J7UW5a6O67qX0KWKS3/pu0m4w==", + "dev": true, + "dependencies": { + "tslib": "^2.1.0" + } + }, + "node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==", + "dev": true + } + }, + "dependencies": { + "rxjs": { + "version": "7.5.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.2.tgz", + "integrity": "sha512-PwDt186XaL3QN5qXj/H9DGyHhP3/RYYgZZwqBv9Tv8rsAaiwFH1IsJJlcgD37J7UW5a6O67qX0KWKS3/pu0m4w==", + "dev": true, + "requires": { + "tslib": "^2.1.0" + } + }, + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==", + "dev": true + } + } } diff --git a/package.json b/package.json index bc46d6b..aac3777 100644 --- a/package.json +++ b/package.json @@ -15,5 +15,8 @@ "types": "./index.d.ts", "optionalDependencies": { "rxjs": "*" + }, + "devDependencies": { + "rxjs": "^7.5.2" } } diff --git a/rxjs/index.d.ts b/rxjs/index.d.ts index 62bdce4..0a1a6a0 100644 --- a/rxjs/index.d.ts +++ b/rxjs/index.d.ts @@ -1,14 +1,14 @@ /** * 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' type ObservedValue = A['length'] extends 0 ? void : @@ -16,10 +16,20 @@ type ObservedValue = A interface FromTypedEvent { - < Emitter extends TypedEventEmitter + < Emitter extends TypedEmitter , EventName extends keyof Events - , Events = Emitter extends TypedEventEmitter ? T : never - >(emitter: Emitter, event: EventName): Observable any ? A : never>> + , Events = Emitter extends TypedEmitter ? T : never + >(emitter: Emitter, event: EventName): Observable any ? A : never>> } export type FromEvent = FromTypedEvent & typeof rxFromEvent + +interface TypedEmitter extends BaseTypedEmitter { + /** + * required by `FromEvent` + * @see https://github.com/devanshj/rxjs-from-emitter/issues/4#issuecomment-665104646 + */ + __events: Events +} + +export default TypedEmitter