EVT
Search…
Evt.factorize(evt)
This is the identity function with special type annotations.
If you have a variable that is either an Evt that post A or an Evt that post B you have an event that post A or B.
In other words Evt<A> | Evt<B> is assignable to Evt<A | B >. This method implement this proerty.
1
import { Evt, VoidEvt, matchVoid } from "evt";
2
3
declare evt: Evt<string> | Evt<number> | VoidEvt = Evt.create<any>();
4
5
evt.attach(data=> { }); // TS ERROR
6
7
Evt.factorize(evt) // OK, return Evt<string | number | void>
8
.attach(data=> { // data is string | number | void
9
10
//To test if data is void
11
if( matchVoid(data) ){
12
return;
13
}
14
15
//Here data is string | number.
16
17
})
18
;
Copied!
See also FactorizeEvt<E>, helper type that this method levrage.
Last modified 1yr ago
Copy link