Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

events dispatchEvent typing #317

Closed
tabcat opened this issue Dec 5, 2022 · 3 comments · Fixed by #319
Closed

events dispatchEvent typing #317

tabcat opened this issue Dec 5, 2022 · 3 comments · Fixed by #319
Assignees

Comments

@tabcat
Copy link
Contributor

tabcat commented Dec 5, 2022

Is there any way to type check the Event.type and .detail for dispatchEvent similar to the add/removeEventListener methods?

dispatchEvent (event: Event): boolean {
const result = super.dispatchEvent(event)
let list = this.#listeners.get(event.type)
if (list == null) {
return result
}
list = list.filter(({ once }) => !once)
this.#listeners.set(event.type, list)
return result
}

@mpetrunic
Copy link
Member

Unfortunately, the Event type is of type string and there is no way to type-check it. I'm proposing new method with type safety here: #319

@achingbrain achingbrain added the status/in-progress In progress label Jan 10, 2023
achingbrain added a commit that referenced this issue Jan 17, 2023
Adds a type-safe `safeDispatchEvent` method to the `EventEmitter` interface that allows type checking of dispatched events.

resolves #317 

Co-authored-by: Alex Potsides <[email protected]>
github-actions bot pushed a commit that referenced this issue Jan 17, 2023
## [@libp2p/interfaces-v3.3.0](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interfaces-v3.2.0...@libp2p/interfaces-v3.3.0) (2023-01-17)

### Features

* safe dispatch event ([#319](#319)) ([8caeee8](8caeee8)), closes [#317](#317)

### Trivial Changes

* remove lerna ([#330](#330)) ([6678592](6678592))
@github-actions
Copy link

🎉 This issue has been resolved in version @libp2p/interfaces-v3.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Jan 17, 2023
@github-actions
Copy link

🎉 This issue has been resolved in version @libp2p/interface-mocks-v9.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants