types.ts
This file
Path
test/types.ts
20 lines · 497 bytes · TypeScript
Last changed by
Export Mitt types for TS consumers (#101)Jack Franklinbefore adoptioneb2be7c
History of this fileTake it
Export Mitt types for TS consumers (#101)Jack Franklinbefore adoptioneb2be7c
lines 1–20why, one step back1import mitt, { EventHandlerList, EventHandlerMap } from '..';23const events = mitt();4function foo() {}5events.on('foo', foo);6events.emit('foo', 'hello');78// handler return type should be ignored:9events.on('foo', async e => e * 42);1011// event map type12const map = new Map<string, EventHandlerList>([13 ['foo', [foo]]14]);15const events2 = mitt(map);16events2.emit('foo', 'hello');1718// event map type & iterables19const map2 : EventHandlerMap = new Map(Object.entries(({ foo: [foo] })));20mitt(map2);