Open Yuddomack opened 2 years ago
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.
multiple parameter passing is possible by this
call(...arg) { handlers.forEach((fn) => fn && fn(...arg)); }
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)); }, // ...
Please consider to this pull request! and Thank you for providing a good ecosystem!
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
+ Additionally
multiple parameter passing is possible by this
if you don't think need multi parameter, can change like this
EventType
Events.call
Thank you
Please consider to this pull request! and Thank you for providing a good ecosystem!