Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type arithmetic to improve event type-safety (#705)
This PR just adds some utility types that improve type-safety on event types. They are currently not used, but I figured that it was worth including it in a separate PR since it is rather dense code that takes some time to get used to. ### Test Plan Example of it in action: ```ts const eventData: AnyEvent<BatchExchange> = {} as any switch (eventData.event) { case "Token": // ERR break case "OrderPlacement": eventData.returnValues.buyToken = "asdf" // OK break case "Withdraw": eventData.returnValues.buyToken = "asdf" // ERR break } ``` Produces the folling `tsc` errors: ``` src/streamed/events.ts(50,8): error TS2678: Type '"Token"' is not comparable to type '"OrderPlacement" | "TokenListing" | "OrderCancellation" | "OrderDeletion" | "Trade" | "TradeReversion" | "SolutionSubmission" | "Deposit" | "WithdrawRequest" | "Withdraw"'. src/streamed/events.ts(56,28): error TS2339: Property 'buyToken' does not exist on type '{ user: string; token: string; amount: string; 0: string; 1: string; 2: string; }'. ```
- Loading branch information