aboutsummaryrefslogtreecommitdiff
path: root/test/types.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/types.ts')
-rw-r--r--test/types.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/types.ts b/test/types.ts
new file mode 100644
index 0000000..23334bb
--- /dev/null
+++ b/test/types.ts
@@ -0,0 +1,20 @@
+import 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 type
+const map = new Map<string, EventHandlerList>([
+ ['foo', [foo]]
+]);
+const events2 = mitt(map);
+events2.emit('foo', 'hello');
+
+// event map type & iterables
+const map2 : EventHandlerMap = new Map(Object.entries(({ foo: [foo] })));
+mitt(map2);