New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow symbol event names #43
Conversation
@sindresorhus Lemme know if we want this temporal type relaxation or if we will wait for the typescript patch to land so I could update docs accordingly. |
Doesn't look like the TypeScript project will fix this anytime soon, so let's do it this way. Don't forget to update the docs. |
@stroncium When this is merged, what do you think of dropping emitter.on(Emittery.anyEvent, listener); Would be nice to reduce the API surface. |
@sindresorhus I'd vote against it. |
@sindresorhus Docs didn't mention that what event names are supposed to be anywhere(except type in ts), but I think symbol events are really good and must be used as much as possible, so I took freedom to add a couple lines to example and add notification at the beginning of API docs in |
readme.md
Outdated
@@ -23,17 +23,29 @@ const Emittery = require('emittery'); | |||
|
|||
const emitter = new Emittery(); | |||
|
|||
const myEvent = Symbol('my symbol event'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a better example. This doesn't really show how Symbols can be useful as event names.
}); | ||
|
||
emitter.emit('馃', '馃寛'); | ||
emitter.emit(myEvent, '馃') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this example to the TS file too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have generic usage example in typescript, only examples to clarify some non-obvious things.
@Richienb Can you help review? |
@stroncium Ping! |
Fixes #16
In typescript, complete typing is blocked by microsoft/TypeScript#1863 at the moment, so we relax typing a bit. This relaxation affects defining
EventDataMap
with number indexes, soEmittery.Typed<{123: string}, 'someevent'>
causes no compile time error. However, using any such event will still cause compile time error.馃
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
eventName
IssueHunt has been backed by the following sponsors. Become a sponsor