From 9539abe200172cf98eae41c8da835d89a8c8da4c Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Wed, 23 Jun 2021 10:44:55 -0400 Subject: Merge master --- README.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c0bc4d..0219f3a 100644 --- a/README.md +++ b/README.md @@ -86,11 +86,28 @@ Set `"strict": true` in your tsconfig.json to get improved type inference for `m import mitt from 'mitt'; type Events = { - foo: string - bar?: number -} + foo: string; + bar?: number; +}; -const emitter: mitt.Emitter = mitt(); +const emitter = mitt(); // inferred as Emitter + +emitter.on('foo', (e) => {}); // 'e' has inferred type 'string' + +emitter.emit('foo', 42); // Error: Argument of type 'number' is not assignable to parameter of type 'string'. (2345) +``` + +Alternatively, you can use the provided `Emitter` type: + +```ts +import mitt, { Emitter } from 'mitt'; + +type Events = { + foo: string; + bar?: number; +}; + +const emitter: Emitter = mitt(); ``` ## Examples & Demos -- cgit v1.2.3