-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix __events prop breaking inheritance (#31)
* Add rxjs as dev dependency To get rid of the error in the IDE. * Move `__events` hack into separate interface for rxjs
- Loading branch information
Showing
5 changed files
with
69 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,8 @@ | |
"types": "./index.d.ts", | ||
"optionalDependencies": { | ||
"rxjs": "*" | ||
}, | ||
"devDependencies": { | ||
"rxjs": "^7.5.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
/** | ||
* 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 extends unknown[]> = | ||
A['length'] extends 0 ? void : | ||
A['length'] extends 1 ? A[0] : | ||
A | ||
|
||
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 |