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

suggest to make 'createEvents' type friendley #955

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Yuddomack
Copy link

I was trying to create a custom event for experiment (like this #949)
but did some mistakes because the type was not clear little.

I didn't want to someother make same mistake,
Help them see for themselves what they are doing.

so I added a type specification to help with type inference.

It make improve type inference

before (any) after (inferred)
image image
image image

+ Additionally

multiple parameter passing is possible by this

call(...arg) {
  handlers.forEach((fn) => fn && fn(...arg));
}
before after
image image

if you don't think need multi parameter, can change like this

  • EventType
type Events<F extends EventHandler> = {
  length: number;
  push: (fn: F) => () => void;
  call: (arg: Parameters<F>[0]) => void; // can change optional if need
};
  • Events.call
// ...
call(arg) {
  handlers.forEach((fn) => fn && fn(arg));
},
// ...

Thank you

Please consider to this pull request!
and Thank you for providing a good ecosystem!

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.

2 participants