Improved EventEmitter error handling

Fixed the EventEmitter to preserve the first thrown error while properly reporting subsequent errors instead of silently swallowing them. Added test coverage for this error handling behavior and improved type safety of listener functions.