{"_id":"@livekit/typed-emitter","_rev":"41-e705ce612b087f74626553a75f478b8f","name":"@livekit/typed-emitter","dist-tags":{"latest":"3.0.0"},"versions":{"3.0.0":{"name":"@livekit/typed-emitter","version":"3.0.0","keywords":["event","emitter","typescript","interface"],"author":{"url":"https://github.com/andywer","name":"Andy Wermke"},"license":"MIT","_id":"@livekit/typed-emitter@3.0.0","maintainers":[{"name":"sfkat","email":"kat@livekit.io"},{"name":"braunsteinlivekit","email":"bbraunstein@livekit.io"},{"name":"lk-mike","email":"mike@livekit.io"},{"name":"rektdeckard","email":"friedtm@gmail.com"},{"name":"enbyspace","email":"aoife@livekit.io"},{"name":"kuba--","email":"kuba@livekit.io"},{"name":"lherman-livekit","email":"lherman@livekit.io"},{"name":"paulwe","email":"paulwe@gmail.com"},{"name":"keepingitneil","email":"neil@livekit.io"},{"name":"ocupe_livekit","email":"jonas@livekit.io"},{"name":"cacheonly","email":"donhuh@gmail.com"},{"name":"duanweiwei","email":"duan@livekit.io"},{"name":"benjaminlivekit","email":"benjamin@livekit.io"},{"name":"danm_livekit","email":"dan@livekit.io"},{"name":"feepslk","email":"theo@livekit.io"},{"name":"lukasio","email":"lukas@livekit.io"},{"name":"cnderrauber","email":"jie@livekit.io"},{"name":"lk_hiroshi","email":"hiroshi@livekit.io"},{"name":"dliulk","email":"dl@livekit.io"},{"name":"dc-livekit","email":"dc@livekit.io"},{"name":"shishir.gowda","email":"shishir@livekit.io"},{"name":"raja-livekit","email":"raja@livekit.io"},{"name":"livekitherzog","email":"herzog@livekit.io"},{"name":"matkam_livekit","email":"mat@livekit.io"},{"name":"thedavidzhao","email":"david@davidzhao.com"},{"name":"rdsa","email":"dsa@livekit.io"}],"contributors":[{"url":"https://livekit.io","name":"LiveKit"}],"homepage":"https://github.com/livekit/typed-emitter#readme","bugs":{"url":"https://github.com/livekit/typed-emitter/issues"},"dist":{"shasum":"1a8eb1e68cb163eaad32db6e8356c72bcbe55275","tarball":"https://registry.npmjs.org/@livekit/typed-emitter/-/typed-emitter-3.0.0.tgz","fileCount":5,"integrity":"sha512-9bl0k4MgBPZu3Qu3R3xy12rmbW17e3bE9yf4YY85gJIQ3ezLEj/uzpKHWBsLaDoL5Mozz8QCgggwIBudYQWeQg==","signatures":[{"sig":"MEYCIQCXkbWEvZk1PseeaBReBHwGCTuIaGZNcg92DIyabQzdfgIhAKfa0QhpcoclYJCXyNAUDcO6qWQIUYYhoDlpk8UbJQYv","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6512},"main":"./types.js","types":"./index.d.ts","gitHead":"184237f9f3c09382132141d869124c80b42af57c","_npmUser":{"name":"enbyspace","email":"aoife@livekit.io"},"repository":{"url":"git+https://github.com/livekit/typed-emitter.git","type":"git"},"_npmVersion":"10.7.0","description":"Strictly typed event emitter interface for TypeScript 3. Original Implementation by Andy Wermke (https://github.com/andywer)","directories":{},"_nodeVersion":"20.15.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/typed-emitter_3.0.0_1726302073572_0.13242513911072873","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-09-14T08:21:13.571Z","modified":"2026-09-25T17:16:22.431Z","3.0.0":"2024-09-14T08:21:13.754Z"},"bugs":{"url":"https://github.com/livekit/typed-emitter/issues"},"author":{"url":"https://github.com/andywer","name":"Andy Wermke"},"license":"MIT","homepage":"https://github.com/livekit/typed-emitter#readme","keywords":["event","emitter","typescript","interface"],"repository":{"url":"git+https://github.com/livekit/typed-emitter.git","type":"git"},"description":"Strictly typed event emitter interface for TypeScript 3. Original Implementation by Andy Wermke (https://github.com/andywer)","contributors":[{"url":"https://livekit.io","name":"LiveKit"}],"maintainers":[{"email":"dsa@livekit.io","name":"rdsa"},{"email":"david@davidzhao.com","name":"thedavidzhao"},{"email":"theo@livekit.io","name":"feepslk"},{"email":"mat@livekit.io","name":"matkam_livekit"},{"email":"raja@livekit.io","name":"raja-livekit"},{"email":"herzog@livekit.io","name":"livekitherzog"},{"email":"lukas@livekit.io","name":"lukasio"},{"email":"paulwe@gmail.com","name":"paulwe"},{"email":"dl@livekit.io","name":"dliulk"},{"email":"dan@livekit.io","name":"danm_livekit"},{"email":"jonas@livekit.io","name":"ocupe_livekit"},{"email":"donhuh@gmail.com","name":"cacheonly"},{"email":"kat@livekit.io","name":"sfkat"},{"email":"ben@livekit.io","name":"bcherrylk"},{"email":"friedtm@gmail.com","name":"rektdeckard"},{"email":"jason.lernerman@livekit.io","name":"jason.lernerman"},{"email":"tom.ezquerro@livekit.io","name":"tom.ezquerro"},{"email":"teresa.combs-fisher@livekit.io","name":"tcombsfisher"},{"email":"tina.nguyen@livekit.io","name":"tinalenguyen"},{"email":"thomas.yuill@livekit.io","name":"thomasyuill-livekit"},{"email":"ryan.gaus@livekit.io","name":"rgauslivekit"}],"readme":"> [!NOTE]\n> This is LiveKit's fork of the dormant `typed-emitter` library, which fixes issues with newer\n> ECMAScript targets. It is licensed under the original MIT license, but support will not be\n> provided and pull requests will be closed. Use at your own risk.\n\n# Typed-Emitter\n\n[![NPM Version](https://img.shields.io/npm/v/typed-emitter.svg)](https://www.npmjs.com/package/typed-emitter)\n\nStrictly typed event emitter interface for TypeScript.\n\nCode size: Zero bytes - Just the typings, no implementation. Use the default event emitter of the `events` module in node.js or bring your favorite implementation when writing code for the browser.\n\n\n## Installation\n\n```sh\n$ npm install --save-dev typed-emitter\n\n# Using yarn:\n$ yarn add --dev typed-emitter\n```\n\n\n## Usage\n\n```ts\nimport EventEmitter from \"events\"\nimport TypedEmitter from \"typed-emitter\"\n\n// Define your emitter's types like that:\n// Key: Event name; Value: Listener function signature\ntype MessageEvents = {\n  error: (error: Error) => void,\n  message: (body: string, from: string) => void\n}\n\nconst messageEmitter = new EventEmitter() as TypedEmitter<MessageEvents>\n\n// Good 👍\nmessageEmitter.emit(\"message\", \"Hi there!\", \"no-reply@test.com\")\n\n// TypeScript will catch those mistakes ✋\nmessageEmitter.emit(\"mail\", \"Hi there!\", \"no-reply@test.com\")\nmessageEmitter.emit(\"message\", \"Hi there!\", true)\n\n// Good 👍\nmessageEmitter.on(\"error\", (error: Error) => { /* ... */ })\n\n// TypeScript will catch those mistakes ✋\nmessageEmitter.on(\"error\", (error: string) => { /* ... */ })\nmessageEmitter.on(\"failure\", (error: Error) => { /* ... */ })\n```\n\n## Extending an emitter\n\nYou might find yourself in a situation where you need to extend an event emitter, but also want to strictly type its events. Here is how to.\n\n```ts\nclass MyEventEmitter extends (EventEmitter as new () => TypedEmitter<MyEvents>) {\n  // ...\n}\n```\n\nAs a generic class:\n\n```ts\nclass MyEventEmitter<T> extends (EventEmitter as { new<T>(): TypedEmitter<T> })<T> {\n  // ...\n}\n```\n\n## RxJS `fromEvent` types inference\n\nThe default `fromEvent` from RxJS will return an `Observable<unknown>` for our typed emitter.\n\nThis can be fixed by the following code, by replacing the `fromEvent` type with our enhanced one: `FromEvent`:\n\n```ts\nimport { fromEvent as rxFromEvent } from \"rxjs\"\nimport { default as TypedEmitter, FromEvent } from \"typed-emitter/rxjs\"\n\n// The `Observable` typing can be correctly inferenced\nconst fromEvent = rxFromEvent as FromEvent\n```\n\nLearn more from [rxjs fromEvent compatibility #9](https://github.com/andywer/typed-emitter/issues/9)\nfor the `fromEvent` compatibility discussions.\n\n## Why another package?\n\nThe interface that comes with `@types/node` is not type-safe at all. It does not even offer a way of specifying the events that the emitter will emit...\n\nThe `eventemitter3` package is a popular event emitter implementation that comes with TypeScript types out of the box. Unfortunately there is no way to declare the event arguments that the listeners have to expect.\n\nThere were a few other examples of type-safe event emitter interfaces out there as well. They were either not published to npm, had an inconsistent interface or other limitations.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}