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

Fix Typescript wildcard handler #76

Merged
merged 3 commits into from
Sep 19, 2018

Conversation

zbuttram
Copy link
Contributor

@zbuttram zbuttram commented Jun 22, 2018

Currently the below example will generate an error from Typescript since the Handler type is used for all calls to .on and .off and the Handler signature does not allow for the event type as the first parameter.

import mitt from "mitt";

const emitter = new mitt();

function listenAll(callback: (type: string, event: any) => void) {
	emitter.on('*', callback);
	return () => emitter.off('*', callback);
}

I have introduced a WildcardHandler type that is expected when the first argument to .on or .off is '*'.

It looks like this is already fixed in the Flow types, but Typescript still has the issue.

@anru
Copy link

anru commented Jun 29, 2018

hi @zbuttram, thanks for PR, I've merged it in my fork under emitt package

Copy link
Owner

@developit developit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks.

@developit developit merged commit d08d782 into developit:master Sep 19, 2018
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.

3 participants