You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> tsc asd.ts
asd.ts:20:11 - error TS2344: Type 'ChangeEvent' does not satisfy the constraint 'any[]'.
Type 'ChangeEvent' is missing the following properties from type 'any[]': length, pop, push, concat, and 29 more.
20 podium.on<ChangeEvent>({ name: 'change' }, (event) => {
~~~~~~~~~~~
asd.ts:24:25 - error TS2345: Argument of type '{ table: string; change: string; }' is not assignable to parameter of type '[data: ChangeEvent]'.
Object literal may only specify known properties, and 'table' does not exist in type '[data: ChangeEvent]'.
24 podium.emit('change', { table:'foo', change: 'bar' });
~~~~~~~~~~~
Found 2 errors in the same file, starting at: asd.ts:20
What result did you expect?
I should be able to emit one event (not an array) and manage one item in the listener.
To let it works, here is a workaround: note the ChangeEvent[] and the [{ table: 'foo'...}] (as an array) but the types in the listener is not an array, but a ChangeEvent
podium.on<ChangeEvent[]>({name: 'change'},(event)=>{console.log(event.table);// ! wrong type, it is an array});podium.emit('change',[{table: 'foo',change: 'bar'}]);
The text was updated successfully, but these errors were encountered:
As it is, the .on() generics are not intended to be explicitly defined, only inferred. How does it work without defining it? Ie. podium.on(…).
As for .emit(), it seems that the typings incorrectly assume that spread is always applied to the event when custom events are supplied, thus expecting an array for the second argument. I'm not sure there is a reasonable way to fix this given the stateful nature of the option. Maybe just accept both variants for now?
Support plan
any
)Context
node version: 18
module version with issue: 5.0.0
last module version without issue: 4.1.3
environment (e.g. node, browser, native): nodejs
used with (e.g. hapi application, another framework, standalone, ...): hapi
typescript: 4.9.4
What are you trying to achieve or the steps to reproduce?
What was the result you got?
compiling errors
What result did you expect?
I should be able to emit one event (not an array) and manage one item in the listener.
To let it works, here is a workaround: note the
ChangeEvent[]
and the[{ table: 'foo'...}]
(as an array) but the types in the listener is not an array, but aChangeEvent
The text was updated successfully, but these errors were encountered: