I want to develop a strict event emitter for TypeScript, but I'm not sure if it can be done.
Let's say I create a listener for my emitter:
// define listener
@listen('my-custom-event')
function userListener(data: IUser){
// handle data
}
In this case, I hope TypeScript will verify that the data being sent is of type IUser.
// success case
myEmitter.emit('my-custom-event', myUser as IUser);
// should result in an error
myEmitter.emit('my-custom-event', myNonUser);
Can this be achieved?