After recently diving into Typescript, I encountered an issue when using EventEmitter from the ThreeJS library.
Whenever I attempt to trigger an event:
const event: THREE.EventDispatcher = new THREE.EventDispatcher();
event.addEventListener('test', () => console.log(1));
event.dispatchEvent({ type: 'test' }); // <-- error
An error pops up, stating:
TS2345: Argument of type
'{ type: string; }'
is not assignable to parameter of type'never'
.
To work around this issue, I tried the following approach:
const event: THREE.EventDispatcher = new THREE.EventDispatcher();
event.addEventListener('test', () => console.log(1));
event.dispatchEvent<any>({ type: 'test' }); // <-- ignored error by any
Despite finding a temporary fix with 'any', it doesn't feel like the optimal solution. Could someone demonstrate the correct method along with explanations?