Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Nov 14, 2021
1 parent 3c3369f commit 14d2e19
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/puppet/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface PuppetEventListener {
scan : PuppetScanListener
}

const PuppetEventEmitter = EventEmitter as any as new () =>
const PuppetEventEmitter = EventEmitter as unknown as new () =>
TypedEventEmitter<PuppetEventListener>

type PuppetEventName = keyof PuppetEventListener
Expand Down
57 changes: 32 additions & 25 deletions tests/from-event-type.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import {

import {
Observable,
fromEvent,
firstValueFrom,
} from 'rxjs'
fromEvent as rxFromEvent,
} from 'rxjs'
import type {
JQueryStyleEventEmitter,
} from 'rxjs/internal/observable/fromEvent.js'
FromEvent,
} from 'typed-emitter/rxjs'
// import type {
// JQueryStyleEventEmitter,
// } from 'rxjs/internal/observable/fromEvent.js'

import type {
EventLoginPayload,
EventScanPayload,
} from '../src/schemas/mod.js'
import {
Expand All @@ -24,26 +26,32 @@ import {

import { PuppetTest } from './fixtures/puppet-test/puppet-test.js'

test('Puppet satisfy DOM EventTarget: HasEventTargetAddRemove', async t => {
const puppet = new PuppetTest()
/**
* Huan(202111): fromEvent + typed-emitter/rxjs
* @see https://github.com/andywer/typed-emitter/pull/19
*/
const fromEvent: FromEvent = rxFromEvent

// Huan(202110): do not use `tsd` module because the TypeScript version conflict
// - https://github.com/SamVerschueren/tsd/issues/122
//
// expectAssignable<
// JQueryStyleEventEmitter<
// any,
// EventScanPayload | EventLoginPayload
// >
// >(puppet)
// test('Puppet satisfy DOM EventTarget: HasEventTargetAddRemove', async t => {
// const puppet = new PuppetTest()

const target: JQueryStyleEventEmitter<
any,
EventScanPayload | EventLoginPayload
> = puppet
void target
t.pass('expectAssignable match listener argument typings')
})
// // Huan(202110): do not use `tsd` module because the TypeScript version conflict
// // - https://github.com/SamVerschueren/tsd/issues/122
// //
// // expectAssignable<
// // JQueryStyleEventEmitter<
// // any,
// // EventScanPayload | EventLoginPayload
// // >
// // >(puppet)

// const target: JQueryStyleEventEmitter<
// any,
// EventScanPayload | EventLoginPayload
// > = puppet
// void target
// t.pass('expectAssignable match listener argument typings')
// })

test('RxJS: fromEvent type inference', async t => {
const puppet = new PuppetTest()
Expand All @@ -52,9 +60,8 @@ test('RxJS: fromEvent type inference', async t => {
* Issue #96: Add Typing support for RxJS fromEvent
* - https://github.com/wechaty/wechaty-puppet/issues/96
*
* FIXME(202106): get inference from on/off typings
*/
const event$ = fromEvent<EventScanPayload>(puppet, 'scan')
const event$ = fromEvent(puppet, 'scan')

const typeTest: AssertEqual<Observable<EventScanPayload>, typeof event$> = true
t.ok(typeTest, 'should be equal type')
Expand Down

0 comments on commit 14d2e19

Please sign in to comment.