andywer / typed-emitter

🔩 Type-safe event emitter interface for TypeScript
MIT License
268 stars 24 forks source link

feat(fromEvent): add FromEvent type export #19

Closed huan closed 2 years ago

huan commented 2 years ago

This PR tries to implement the discussion from #9

huan commented 2 years ago

Great to know that you think this PR is good!

I have followed your suggestion and finished the modifications.

Please let me know if there's any other suggestion so we can continue improving it, and I'm looking forward to installing this feature from NPM! (before the RxJS v8 remove the fromEvent<T> for Node.js EventEmitter ;-)

andywer commented 2 years ago

@huan Cool. I'm just thinking what the next steps are.

How about this: Let's already publish a pre-release version to npm (v1.5.0-rc?) from the feature branch, without updating the latest tag on npm, so you can install it manually from npm, but it's only opt-in until we merge and publish the update.

Btw, I didn't quite get this bit:

(before the RxJS v8 remove the fromEvent for Node.js EventEmitter ;-)

huan commented 2 years ago

Thanks, publishing a pre-release version to npm as v1.5.0-rc is good to me, I'll test it in my project after it has been published.

Btw, I didn't quite get this bit: "before the RxJS v8 remove the fromEvent for Node.js EventEmitter ;-)"

The fromEvent<T>() that can only work with my Node.js EventEmitter code has been flagged as deprecated, and said that it will be removed after RxJS v8:

/* @deprecated Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. /

See: https://github.com/ReactiveX/rxjs/blob/ecbc6c1178b528b95c44aed5c145b4e6cf7df173/src/internal/observable/fromEvent.ts#L82

I don't know if the RxJS team has already a better solution for this, but for now, it's the only one I can use.

andywer commented 2 years ago

@huan Sorry for the delay! Published commit e581f3a1df7bb2e5c0825f6dc61f3217db6ec9f1 as typed-emitter@1.5.0-from-event under tag testing.

huan commented 2 years ago

I have used it and everything working as expected so far:

https://github.com/wechaty/puppet/blob/f0b28519b072586f48febb383322c5e06cc9deda/tests/from-event-type.spec.ts#L33

Thank you very much for publishing this new feature!