Skip to content

Commit 3483e1a

Browse files
committed
Add generic for mitt event handlers
1 parent 0476b70 commit 3483e1a

File tree

1 file changed

+5
-5
lines changed
  • packages/next/next-server/lib

1 file changed

+5
-5
lines changed

packages/next/next-server/lib/mitt.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1515
// See the LICENSE at the top of the file
1616

1717
type Handler = (...evts: any[]) => void
18-
export default function mitt<T extends string>() {
19-
const all: Record<T, Handler[]> = Object.create(null)
18+
export default function mitt<T extends string, H extends Handler = Handler>() {
19+
const all: Record<T, H[]> = Object.create(null)
2020
return {
21-
on(type: T, handler: Handler) {
21+
on(type: T, handler: H) {
2222
;(all[type] || (all[type] = [])).push(handler)
2323
},
24-
off(type: T, handler: Handler) {
24+
off(type: T, handler: H) {
2525
if (all[type]) {
2626
// tslint:disable-next-line:no-bitwise
2727
all[type].splice(all[type].indexOf(handler) >>> 0, 1)
2828
}
2929
},
3030
emit(type: T, ...evts: any[]) {
3131
// eslint-disable-next-line array-callback-return
32-
;(all[type] || []).slice().map((handler: Handler) => {
32+
;(all[type] || []).slice().map((handler: H) => {
3333
handler(...evts)
3434
})
3535
},

0 commit comments

Comments
 (0)