File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -86,11 +86,28 @@ Set `"strict": true` in your tsconfig.json to get improved type inference for `m
86
86
import mitt from ' mitt' ;
87
87
88
88
type Events = {
89
- foo: string
90
- bar? : number
91
- }
89
+ foo: string ;
90
+ bar? : number ;
91
+ };
92
92
93
- const emitter: mitt .Emitter <Events > = mitt <Events >();
93
+ const emitter = mitt <Events >(); // inferred as Emitter<Events>
94
+
95
+ emitter .on (' foo' , (e ) => {}); // 'e' has inferred type 'string'
96
+
97
+ emitter .emit (' foo' , 42 ); // Error: Argument of type 'number' is not assignable to parameter of type 'string'. (2345)
98
+ ```
99
+
100
+ Alternatively, you can use the provided ` Emitter ` type:
101
+
102
+ ``` ts
103
+ import mitt , { Emitter } from ' mitt' ;
104
+
105
+ type Events = {
106
+ foo: string ;
107
+ bar? : number ;
108
+ };
109
+
110
+ const emitter: Emitter <Events > = mitt <Events >();
94
111
```
95
112
96
113
## Examples & Demos
You can’t perform that action at this time.
0 commit comments