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
123456789101112131415161718192021import mitt, { EventHandlerList, EventHandlerMap } from '..';
const events = mitt();function foo() {}events.on('foo', foo);events.emit('foo', 'hello');
// handler return type should be ignored:events.on('foo', async e => e * 42);
// event map typeconst map = new Map<string, EventHandlerList>([ ['foo', [foo]]]);const events2 = mitt(map);events2.emit('foo', 'hello');
// event map type & iterablesconst map2 : EventHandlerMap = new Map(Object.entries(({ foo: [foo] })));mitt(map2);