Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

fix: event emitter types with local types #80

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/pubsub/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict'

const debug = require('debug')
const { EventEmitter } = require('events')
/** @typedef {import('../types').EventEmitterFactory} Events */
/** @type Events */
const EventEmitter = require('events')
const errcode = require('err-code')

const { pipe } = require('it-pipe')
Expand Down
4 changes: 3 additions & 1 deletion src/pubsub/peer-streams.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'

const { EventEmitter } = require('events')
/** @typedef {import('../types').EventEmitterFactory} Events */
/** @type Events */
const EventEmitter = require('events')

const lp = require('it-length-prefixed')

Expand Down
18 changes: 18 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface EventEmitterFactory {
new(): EventEmitter;
}

export interface EventEmitter {
addListener(event: string | symbol, listener: (...args: any[]) => void);
on(event: string | symbol, listener: (...args: any[]) => void);
once(event: string | symbol, listener: (...args: any[]) => void);
removeListener(event: string | symbol, listener: (...args: any[]) => void);
off(event: string | symbol, listener: (...args: any[]) => void);
removeAllListeners(event?: string | symbol);
setMaxListeners(n: number);
getMaxListeners(): number;
listeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types
rawListeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types
emit(event: string | symbol, ...args: any[]): boolean;
listenerCount(event: string | symbol): number;
}