I just started using Typescript and ran into a problem when working with EventEmitter from the ThreeJS library.
When I try to dispatch an event:
const event: THREE.EventDispatcher = new THREE.EventDispatcher();
event.addEventListener('test', () => console.log(1));
event.dispatchEvent({ type: 'test' }); // <-- error
I get an error:
TS2345: Argument of type
'{ type: string; }'
is not assignable to parameter of type'never'
.
But it works if I do it like this:
const event: THREE.EventDispatcher = new THREE.EventDispatcher();
event.addEventListener('test', () => console.log(1));
event.dispatchEvent<any>({ type: 'test' }); // <-- ignored error by any
But it seems to me that this is a bad solution, could you show me how to do it correctly with explanations