Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove onAny generic #28

Merged
merged 2 commits into from Jan 17, 2018
Merged

Remove onAny generic #28

merged 2 commits into from Jan 17, 2018

Conversation

novemberborn
Copy link
Collaborator

Before, you could do:

import Emittery = require('emittery')

const e = new Emittery.Typed<{foo: 'bar'}, 'baz'>()
e.onAny<'foo'>((eventName, eventData) => {
})

This is incorrect, since e.emit('baz') is allowed.

Note that TypeScript can't express the type of eventData based on eventName. Thus eventData will be the union of 'bar' | undefined. I guess it's an encouragement for adding regular listeners instead.

I also noticed that new Emittery.Typed<{}, true>() was allowed. Empty event names must still be strings.

/cc @dinoboff.

Specifying the expected event name through the generic isn't sensible
for `onAny()`. Loosen the listener definition so `eventName` can be all
specified event names, and `eventData` can be `undefined`. Unfortunately
this will also be the case if `EmptyEvents` is `never`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants