{"_id":"strict-event-emitter-types","_rev":"8-aa7f9aa64b0200c24e0c6de4e6107f36","name":"strict-event-emitter-types","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"strict-event-emitter-types","version":"1.0.0","description":"Strictly and safely type any EventEmitter-like interface on any object","main":"dist/src/index.js","scripts":{"build":"tsc"},"types":"types/src","repository":{"type":"git","url":"git+https://github.com/bterlson/typed-event-emitter.git"},"keywords":["TypeScript","TS","EventEmitter","events"],"author":{"name":"Brian Terlson","email":"brian.terlson@microsoft.com"},"license":"ISC","bugs":{"url":"https://github.com/bterlson/typed-event-emitter/issues"},"homepage":"https://github.com/bterlson/typed-event-emitter#readme","dependencies":{},"devDependencies":{"@types/node":"^9.4.6","dtslint":"^0.2.0","typescript":"^2.8.0-dev.20180301"},"gitHead":"d2c0668daa1af6b839072d2bbd6fc05cd0776292","_id":"strict-event-emitter-types@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.2.1","_npmUser":{"name":"bterlson","email":"brian.terlson@microsoft.com"},"dist":{"integrity":"sha512-rFOrezFRH/IugsIvde/EmeyShPg2N0FDXu7c6HQGSfauDAaluAXRs03jMgpkHcFAbz0Y/WehGeVrWkRzHN4cTw==","shasum":"4cf98bb28742a39fc25b2c31e2f64612d894c6d0","tarball":"https://registry.npmjs.org/strict-event-emitter-types/-/strict-event-emitter-types-1.0.0.tgz","fileCount":7,"unpackedSize":12887,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID1BYDcegHL6mgv87GenYt45EPZxHI1pl5gU45nrK96AAiAUMEC+F45J4it1UJZw3KtXzuKiFcH5ewpAFojGNJ76uA=="}]},"maintainers":[{"name":"bterlson","email":"brian.terlson@microsoft.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strict-event-emitter-types_1.0.0_1520276486901_0.8737632117670036"},"_hasShrinkwrap":false},"1.0.1":{"name":"strict-event-emitter-types","version":"1.0.1","description":"Strictly and safely type any EventEmitter-like interface on any object","main":"dist/src/index.js","scripts":{"build":"tsc"},"types":"types/src","repository":{"type":"git","url":"git+https://github.com/bterlson/typed-event-emitter.git"},"keywords":["TypeScript","TS","EventEmitter","events"],"author":{"name":"Brian Terlson","email":"brian.terlson@microsoft.com"},"license":"ISC","bugs":{"url":"https://github.com/bterlson/typed-event-emitter/issues"},"homepage":"https://github.com/bterlson/typed-event-emitter#readme","dependencies":{},"devDependencies":{"@types/node":"^9.4.6","dtslint":"^0.2.0","typescript":"^2.8.0-dev.20180301"},"gitHead":"d85e6df8ba23397c6a9c5d692d00f3b2c0bb8be4","_id":"strict-event-emitter-types@1.0.1","_npmVersion":"5.5.1","_nodeVersion":"8.2.1","_npmUser":{"name":"bterlson","email":"brian.terlson@microsoft.com"},"dist":{"integrity":"sha512-SzFmcgzvZt3Imz3tEa5yg37HbMPm2OueSdoK4McQ62Hh4Hu3nNV21mEJ9kyUh8KAPhqZPBc/o29ke8IIN3z0YA==","shasum":"6a857df731be43d19c28e817ace5484909cb67c1","tarball":"https://registry.npmjs.org/strict-event-emitter-types/-/strict-event-emitter-types-1.0.1.tgz","fileCount":7,"unpackedSize":12889,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIARJ9VkQ5HEZOQNKJ4vasJv99nW51G7/7zOjz5JXsXkLAiEAxSyIX73oc9x+5+vF07xDSFRiQYQRWzZscwH0OGVyoyM="}]},"maintainers":[{"name":"bterlson","email":"brian.terlson@microsoft.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strict-event-emitter-types_1.0.1_1520285501296_0.024946817617084616"},"_hasShrinkwrap":false},"1.0.2":{"name":"strict-event-emitter-types","version":"1.0.2","description":"Strictly and safely type any EventEmitter-like interface on any object","main":"dist/src/index.js","scripts":{"build":"tsc"},"types":"types/src","repository":{"type":"git","url":"git+https://github.com/bterlson/typed-event-emitter.git"},"keywords":["TypeScript","TS","EventEmitter","events"],"author":{"name":"Brian Terlson","email":"brian.terlson@microsoft.com"},"license":"ISC","bugs":{"url":"https://github.com/bterlson/typed-event-emitter/issues"},"homepage":"https://github.com/bterlson/typed-event-emitter#readme","dependencies":{},"devDependencies":{"@types/node":"^9.4.6","dtslint":"^0.2.0","typescript":"next"},"gitHead":"777d71edb3cffa2b812327aefc8042a5118e2673","_id":"strict-event-emitter-types@1.0.2","_npmVersion":"5.5.1","_nodeVersion":"8.2.1","_npmUser":{"name":"bterlson","email":"brian.terlson@microsoft.com"},"dist":{"integrity":"sha512-WZ8RR88YVdy8hVGxic+ivRqGznL00+u37tZEo6TgJYO/RL6Gs+qlD8+jVOmK1OmMe5aWAbrCpyEwr5N138Z9pA==","shasum":"19f850321e63c657b213d555e68ec31aad6f7c2e","tarball":"https://registry.npmjs.org/strict-event-emitter-types/-/strict-event-emitter-types-1.0.2.tgz","fileCount":7,"unpackedSize":12873,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBLvZndXWsn4g5j4czX2L5eK+2jUoZjU58MtChcIo0eZAiBByHgvF4Aad4f/bT2Ku/Be7RKEW71IPBRy87RdyURf/g=="}]},"maintainers":[{"name":"bterlson","email":"brian.terlson@microsoft.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strict-event-emitter-types_1.0.2_1520294383700_0.1607717870413412"},"_hasShrinkwrap":false},"1.0.3":{"name":"strict-event-emitter-types","version":"1.0.3","description":"Strictly and safely type any EventEmitter-like interface on any object","main":"dist/src/index.js","scripts":{"build":"tsc","prepublish":"npm run build"},"types":"types/src","repository":{"type":"git","url":"git+https://github.com/bterlson/typed-event-emitter.git"},"keywords":["TypeScript","TS","EventEmitter","events"],"files":["types"],"author":{"name":"Brian Terlson","email":"brian.terlson@microsoft.com"},"license":"ISC","bugs":{"url":"https://github.com/bterlson/typed-event-emitter/issues"},"homepage":"https://github.com/bterlson/typed-event-emitter#readme","dependencies":{},"devDependencies":{"@types/node":"^9.4.6","typescript":"next"},"gitHead":"f63e3dccff231659f26e67b56e7a240026fdbca8","_id":"strict-event-emitter-types@1.0.3","_npmVersion":"5.7.1","_nodeVersion":"8.2.1","_npmUser":{"name":"bterlson","email":"brian.terlson@microsoft.com"},"dist":{"integrity":"sha512-TIJC1B1xZOd0mCa4IJ1sRp1+KEJMxV1q9Rkpm87sCnT/VCWXLdEe+9btVSc2+Iflr4hsg1rBw4pqVae/q4FTmQ==","shasum":"79179754a6a3a7171678f03c91c866f604391248","tarball":"https://registry.npmjs.org/strict-event-emitter-types/-/strict-event-emitter-types-1.0.3.tgz","fileCount":5,"unpackedSize":6769,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFlF+qMit0K7bwRndOTpIymt5Zb+m8IPthTopnzMuME1AiAUa53qRF4hQP0LMNu4PM/4p9zZg0GnZrl5dsoPIIpZEA=="}]},"maintainers":[{"name":"bterlson","email":"brian.terlson@microsoft.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strict-event-emitter-types_1.0.3_1521633098283_0.49692968279987815"},"_hasShrinkwrap":false},"1.1.0":{"name":"strict-event-emitter-types","version":"1.1.0","description":"Strictly and safely type any EventEmitter-like interface on any object","main":"dist/src/index.js","scripts":{"build":"tsc","prepublish":"npm run build"},"types":"types/src","repository":{"type":"git","url":"git+https://github.com/bterlson/typed-event-emitter.git"},"keywords":["TypeScript","TS","EventEmitter","events"],"files":["types"],"author":{"name":"Brian Terlson","email":"brian.terlson@microsoft.com"},"license":"ISC","bugs":{"url":"https://github.com/bterlson/typed-event-emitter/issues"},"homepage":"https://github.com/bterlson/typed-event-emitter#readme","dependencies":{},"devDependencies":{"@types/node":"^9.4.6","typescript":"next"},"gitHead":"3150dff99fb491996dc025ee8ca5282dcb0b47a8","_id":"strict-event-emitter-types@1.1.0","_npmVersion":"5.7.1","_nodeVersion":"8.2.1","_npmUser":{"name":"bterlson","email":"brian.terlson@microsoft.com"},"dist":{"integrity":"sha512-BGtvvEOvs0x83cuVBcaFrQkBAQYVtO+7N47/xAdXtayoQtbpzuM8im4uDp54hpzqS0WAPrbEiJagU1uKkmtHSg==","shasum":"6250e564a1cffefeb0482d1c620f42b2f9f0bf33","tarball":"https://registry.npmjs.org/strict-event-emitter-types/-/strict-event-emitter-types-1.1.0.tgz","fileCount":5,"unpackedSize":6768,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA9Wa9PQmVv1QGB3I3qJsNBnLyd3OhZ4QkTfoNbNd0c6AiEA0OyMEFlfcRj0Wf2r9NgHjkcB/u46dmUZa9/4sOZmc9g="}]},"maintainers":[{"name":"bterlson","email":"brian.terlson@microsoft.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strict-event-emitter-types_1.1.0_1522961211968_0.08118947130464238"},"_hasShrinkwrap":false},"1.2.0":{"name":"strict-event-emitter-types","version":"1.2.0","description":"Strictly and safely type any EventEmitter-like interface on any object","main":"dist/src/index.js","scripts":{"build":"tsc","prepublish":"npm run build"},"types":"types/src","repository":{"type":"git","url":"git+https://github.com/bterlson/typed-event-emitter.git"},"keywords":["TypeScript","TS","EventEmitter","events"],"files":["types"],"author":{"name":"Brian Terlson","email":"brian.terlson@microsoft.com"},"license":"ISC","bugs":{"url":"https://github.com/bterlson/typed-event-emitter/issues"},"homepage":"https://github.com/bterlson/typed-event-emitter#readme","dependencies":{},"devDependencies":{"@types/node":"^9.4.6","typescript":"next"},"gitHead":"c2354c5bb4003c120e7aa1a059a28cb15dd5964b","_id":"strict-event-emitter-types@1.2.0","_npmVersion":"5.7.1","_nodeVersion":"8.2.1","_npmUser":{"name":"bterlson","email":"brian.terlson@microsoft.com"},"dist":{"integrity":"sha512-KqQQvQapOVn99SI/L6tEnW2mDXWddzlr+D1AAmiaXqI7Annq2hbfac8XnZzZHXOV50dCKtUsw1OCNjCezFHAMw==","shasum":"00c413587c0cf7d5b7acb70ce9aa75526b36601c","tarball":"https://registry.npmjs.org/strict-event-emitter-types/-/strict-event-emitter-types-1.2.0.tgz","fileCount":5,"unpackedSize":7672,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA8kNJVsyMvbmKbpIPk+8i+ztIWNZ/ml0t+4iHls9cIHAiEApcRRUE2XLwU04gNd+JeMMF5Yy1yXP2nAHmARpzbnk2Y="}]},"maintainers":[{"name":"bterlson","email":"brian.terlson@microsoft.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strict-event-emitter-types_1.2.0_1523043398510_0.2984539485130824"},"_hasShrinkwrap":false},"2.0.0":{"name":"strict-event-emitter-types","version":"2.0.0","description":"Strictly and safely type any EventEmitter-like interface on any object","main":"dist/src/index.js","scripts":{"build":"tsc","prepublish":"npm run build"},"types":"types/src","repository":{"type":"git","url":"git+https://github.com/bterlson/typed-event-emitter.git"},"keywords":["TypeScript","TS","EventEmitter","events"],"author":{"name":"Brian Terlson","email":"brian.terlson@microsoft.com"},"license":"ISC","bugs":{"url":"https://github.com/bterlson/typed-event-emitter/issues"},"homepage":"https://github.com/bterlson/typed-event-emitter#readme","dependencies":{},"devDependencies":{"@types/node":"^9.4.6","typescript":"next"},"gitHead":"9887607114d84758c587d53034e5da81892e8654","_id":"strict-event-emitter-types@2.0.0","_npmVersion":"6.3.0","_nodeVersion":"8.2.1","_npmUser":{"name":"bterlson","email":"brian.terlson@microsoft.com"},"dist":{"integrity":"sha512-Nk/brWYpD85WlOgzw5h173aci0Teyv8YdIAEtV+N88nDB0dLlazZyJMIsN6eo1/AR61l+p6CJTG1JIyFaoNEEA==","shasum":"05e15549cb4da1694478a53543e4e2f4abcf277f","tarball":"https://registry.npmjs.org/strict-event-emitter-types/-/strict-event-emitter-types-2.0.0.tgz","fileCount":8,"unpackedSize":10323,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbjXGICRA9TVsSAnZWagAAKRAQAIFPM5o5kExkmqrR/Yel\nE+JZ6r6gXl+xNmzFtx7C7P+G0QuT69Hx8m+HO7TnOEBATjgQowZb3DxsiPcS\nbPAIy24nU4LOWo22Y5p45XoEIf6VQY3hg/jGpZqHO1kzT9TLwFXnzjK1EXle\nfgw2Pcx+VPUzHFeFPZvQkL2rrYW9oZsiWMdW9HRt189JhVdL3sz/uSu9TkVl\nD99IFCh+YaACjScIlJMy0gZTtIwjryWC6fyB1UCTSOFQoYYMX4M8FHY5aanB\nwLon9ZdF/jKq6PGJMQmOVgLxF+uqANnzd5bZckSgONuxkudoRJREeYFQXkw9\npwJjOZqABhRaqYZr7RWvGYIdlv2weLwIn79ZfszggWc+x2cNAgFt6mptLRqs\nlqJ3wswUbM2ke+AaKNAvZGpn/Mv91bc3kjHKftXpX0OZY57WwBP1+MtA7yQd\nRvr0WHRuiVZ0mlPOTLsXyyJfM99AP5fby64aHYYq7zlYaRYoR1+MTZiCfiEw\nI/NqZDQaeKTlQh3vaYpYOQgccbktgnOTO8q7gDFqZ3JHlxlwdW8hHDxalT45\nSPue5LKlmrCdkjPuFV7f9rHS1STxRTygpcKRTYwMnrN2/YIyvrqU8zenUHoR\nouEPYfOwTn2Rb0/bdpBdpxUmrAcZlSxO1cDBxD8TFRsov9WdnpfU/ieNxeQB\nXXrF\r\n=czs8\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDjA1lxl6fFMVhWBkSxI1A2kYoDULcPgwvKiOadR0jI6AIgQBGoyvpKlx5tjY1przgHac2Ne2KoHo967PwZ7y7eUAw="}]},"maintainers":[{"name":"bterlson","email":"brian.terlson@microsoft.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strict-event-emitter-types_2.0.0_1535996296148_0.5022773899882482"},"_hasShrinkwrap":false}},"time":{"created":"2018-03-05T19:01:26.900Z","1.0.0":"2018-03-05T19:01:26.949Z","modified":"2022-05-18T20:33:46.460Z","1.0.1":"2018-03-05T21:31:41.381Z","1.0.2":"2018-03-05T23:59:43.752Z","1.0.3":"2018-03-21T11:51:38.379Z","1.1.0":"2018-04-05T20:46:52.046Z","1.2.0":"2018-04-06T19:36:38.563Z","2.0.0":"2018-09-03T17:38:16.282Z"},"maintainers":[{"name":"bterlson","email":"brian.terlson@microsoft.com"}],"description":"Strictly and safely type any EventEmitter-like interface on any object","homepage":"https://github.com/bterlson/typed-event-emitter#readme","keywords":["TypeScript","TS","EventEmitter","events"],"repository":{"type":"git","url":"git+https://github.com/bterlson/typed-event-emitter.git"},"author":{"name":"Brian Terlson","email":"brian.terlson@microsoft.com"},"bugs":{"url":"https://github.com/bterlson/typed-event-emitter/issues"},"license":"ISC","readme":"## Typed Event Emitter\n\n**NOTE: REQUIRES TYPESCRIPT 3.0**\n\nA TypeScript library for strongly typed event emitters in 0 kB. Declare events using a simple interface mapping event names to their payloads to get stricter versions of `emit`, `on`, and other common EventEmitter APIs. Works with any kind of EventEmitter.\n\n### Installation\n\n```\nnpm i strict-event-emitter-types\n```\n\n### Example\n\n```ts\nimport StrictEventEmitter from 'strict-event-emitter-types';\n\n// define your events\ninterface Events {\n request: (request: Request, response: Response) => void;\n done: void;\n}\n\n// grab an event emitter\nimport { EventEmitter } from 'events';\n\n// Create strict event emitter types\nlet ee: StrictEventEmitter = new EventEmitter;\n\n// now enjoy your strongly typed EventEmitter API!🎉\n\nee.on('request', (r, resp) => ... );\n// r and resp are contextually typed to Request and Response\n\nee.on('somethingElse');\n// Error: unknown event\n\nee.on('done', x => x);\n// Error: The 'done' event does not have a payload\n\nee.emit('request', new Request());\n// Error: missing event payload (the response)\n\nee.emit('request', new Request(), false);\n// Error: incorrect payload type\n```\n\n### Usage\n\n#### Event Records\n\nEvent records are interfaces or object types that map event names to the event's payload types. In the following example, three events are declared:\n\n```ts\ninterface Events {\n req: (request: Request, response: Response) => void;\n done: void;\n conn: Connection;\n}\n```\n\nEach event shows one of three ways to type the event payloads:\n\n1. **Function type:** Parameters are the event payload. The return type is ignored.\n1. **`void`:** A shortcut for an event with no payload, i.e. `() => void`\n1. **Anything else:** A shortcut for an event with one payload, for example `(p: number) => void` can be written as just `number`.\n\n#### StrictEventEmitter<TEmitterType, TEventRecord, TEmitRecord>\n\nThe default export. A generic type that takes three type parameters:\n\n1. _TEmitterType_: Your EventEmitter type (e.g. node's EventEmitter or socket.io socket)\n2. _TEventRecord_: A type mapping event names to event payloads\n3. _TEmitRecord_: Optionally, a similar type mapping things you can emit.\n\nThe third parameter is handy when typing web sockets where client and server can listen to and emit different events. For example, if you are using socket.io:\n\n```ts\n// create types representing the server side and client\n// side sockets\nexport type ServerSocket =\n StrictEventEmitter;\nexport type ClientSocket =\n StrictEventEmitter;\n\n// elsewhere on server\nlet serverSocket: ServerSocket = new SocketIO.Socket();\nserverSocket.on(/* only events that are sent from the client are allowed */, ...)\nserverSocket.emit(/* only events that are emitted from the server are allowed */, ...)\n\n// elsewhere on client\nlet clientSocket: ClientSocket = new SocketIOClient.Socket();\nclientSocket.on(/* only events that are sent from the server are allowed */, ...)\nclientSocket.emit(/* only events that are emitted from the client are allowed */, ...)\n```\n\n##### Usage with Subclasses\n\nTo subclass an EventEmitter you need to cast the base EventEmitter to the strict EventEmitter before extending:\n\n```ts\ntype MyEmitter = StrictEventEmitter;\n\nclass MyEventEmitter extends (EventEmitter as { new(): MyEmitter }) {\n doEmit() {\n this.emit(...); // strict\n }\n}\n```\n\n### StrictBroadcast<TStrictEventEmitter>\n\nA type for a function which takes (and strictly checks) an emit event and a payload. _TStrictEventEmitter_ is the event emitter type instantiated from StrictEventEmitter.\n\nUseful for broadcast abstractions. It is not possible to contextually type assigments to this type, so your declarations will look something like this:\n\n```ts\nimport { StrictBroadcast } from 'strict-event-emitter-types';\n\nconst broadcast: StrictBroadcast = function(\n event: string,\n payload?: any\n) {\n // ...\n};\n```\n\nNote that the loose types for event and payload only apply inside the broadcast function (consumers will see a much stricter signature). Declaring more precise parameter types or narrowing using type guards would allow strongly-typed dispatching to emitters.\n","readmeFilename":"README.md"}