CacheControl / json-rules-engine

A rules engine expressed in JSON
ISC License
2.6k stars 461 forks source link

Type of `Engine.on()` is wrong #295

Open UncleSamSwiss opened 2 years ago

UncleSamSwiss commented 2 years ago

If you register an event handler on a specific event (i.e. Engine.on("my-event", ...)), the first argument of the method will be the params of the Event definition (type: Record<string, any>), not the Event object itself.

I'm not sure if this only the case for specific events or more generally the EventHandler: https://github.com/CacheControl/json-rules-engine/blob/90272d61ed7bea8b7d4000305511e932490d2e2e/types/index.d.ts#L106-L110

greebowarrior commented 2 years ago

I can't speak for the developer (wherever they are), but I think this is intentional, because if you add a listener for a specific 'known' event, the only data you wouldn't know is the event's params. I could be wildly wrong, but it does feel like it should be that way