|
2 | 2 | * The `Event` type represents the strings/symbols used in Node to |
3 | 3 | * identify event types for `EventEmitter` and its subclasses, including |
4 | 4 | * streams, sockets, and servers. |
5 | | - * |
| 5 | + * |
6 | 6 | * Given a type signature `Event.t('a => 'b, 'ty)`, the first type |
7 | 7 | * variable, `'a => 'b`, denotes the type signature of the event listener |
8 | 8 | * function, and `'ty` denotes the type of the associated `EventEmitter`. |
9 | | - * |
| 9 | + * |
10 | 10 | * These abstract `Event.t` types must be passed to `EventEmitter` |
11 | 11 | * functions to register event listeners or emit events. By encoding the |
12 | 12 | * listener function type in a type variable, we can ensure that each |
13 | 13 | * listener has the correct type. The type parameter for the emitter |
14 | 14 | * prevents two different emitters from using each other's events. |
15 | | - * |
| 15 | + * |
16 | 16 | * While this gives us some degree of type safety, it is still possible |
17 | 17 | * to introduce runtime errors with this API. In particular, two or more |
18 | 18 | * `Event.t` types can be defined from the same string/symbol, but with |
19 | 19 | * different listener types. Therefore, we strongly recommend using |
20 | 20 | * 100% unique strings/symbols to define events. |
21 | | - * |
| 21 | + * |
22 | 22 | ") |
23 | 23 | type t<'listener, 'ty> |
24 | 24 | external fromString: string => t<'a => 'b, 'ty> = "%identity" |
| 25 | +external fromString2: string => t<('a, 'b) => 'c, 'ty> = "%identity" |
| 26 | +external fromString3: string => t<('a, 'b, 'c) => 'd, 'ty> = "%identity" |
25 | 27 | external fromSymbol: Js.Types.symbol => t<'a => 'b, 'ty> = "%identity" |
| 28 | +external fromSymbol2: Js.Types.symbol => t<('a, 'b) => 'c, 'ty> = "%identity" |
| 29 | +external fromSymbol3: Js.Types.symbol => t<('a, 'b, 'c) => 'd, 'ty> = "%identity" |
26 | 30 | external unsafeToString: t<'a => 'b, 'ty> => string = "%identity" |
| 31 | +external unsafeToString2: t<('a, 'b) => 'c, 'ty> => string = "%identity" |
| 32 | +external unsafeToString3: t<('a, 'b, 'c) => 'd, 'ty> => string = "%identity" |
27 | 33 | external unsafeToSymbol: t<'a => 'b, 'ty> => Js.Types.symbol = "%identity" |
| 34 | +external unsafeToSymbol2: t<('a, 'b) => 'c, 'ty> => Js.Types.symbol = "%identity" |
| 35 | +external unsafeToSymbol3: t<('a, 'b, 'c) => 'd, 'ty> => Js.Types.symbol = "%identity" |
28 | 36 | type case = |
29 | 37 | | String(string) |
30 | 38 | | Symbol(Js.Types.symbol) |
|
0 commit comments