@@ -16,16 +16,15 @@ See the License for the specific language governing permissions and
1616limitations under the License.
1717*/
1818
19+ // eslint-disable-next-line no-restricted-imports
1920import { EventEmitter } from "events" ;
2021
21- export class ReEmitter {
22- private target : EventEmitter ;
22+ import { ListenerMap , TypedEventEmitter } from "./models/typed-event-emitter" ;
2323
24- constructor ( target : EventEmitter ) {
25- this . target = target ;
26- }
24+ export class ReEmitter {
25+ constructor ( private readonly target : EventEmitter ) { }
2726
28- reEmit ( source : EventEmitter , eventNames : string [ ] ) {
27+ public reEmit ( source : EventEmitter , eventNames : string [ ] ) : void {
2928 for ( const eventName of eventNames ) {
3029 // We include the source as the last argument for event handlers which may need it,
3130 // such as read receipt listeners on the client class which won't have the context
@@ -48,3 +47,19 @@ export class ReEmitter {
4847 }
4948 }
5049}
50+
51+ export class TypedReEmitter <
52+ Events extends string ,
53+ Arguments extends ListenerMap < Events > ,
54+ > extends ReEmitter {
55+ constructor ( target : TypedEventEmitter < Events , Arguments > ) {
56+ super ( target ) ;
57+ }
58+
59+ public reEmit < ReEmittedEvents extends string , T extends Events & ReEmittedEvents > (
60+ source : TypedEventEmitter < ReEmittedEvents , any > ,
61+ eventNames : T [ ] ,
62+ ) : void {
63+ super . reEmit ( source , eventNames ) ;
64+ }
65+ }
0 commit comments