···25252626```typescript
2727const divide = (a: number, b: number): number => {
2828+ // This function lies about its type - it can throw!
2829 if (b === 0) throw new Error("Division by zero")
2930 return a / b
3031}
···3839const processOrder = async (orderId: string): Promise<Order> => {
3940 const order = await db.findOrder(orderId) // Throws if not found
4041 const user = await db.findUser(order.userId) // Throws if not found
4242+4143 await payment.charge(user, order.total) // Throws if declined
4244 await inventory.reserve(order.items) // Throws if out of stock
4345 await email.send(user.email, "Order confirmed") // Throws if invalid email
4646+4447 return order
4548}
4649```
···6063What if errors were part of the return type?
61646265```typescript
6363-const divide = (a: number, b: number): Result<number, DivisionError> => {
6464- if (b === 0) return err({ _tag: "DivisionByZero" })
6565- return ok(a / b)
6666-}
6666+const divide = (a: number, b: number): Result<number, DivisionError> =>
6767+ b === 0 ? err({ _tag: "DivisionByZero" }) : ok(a / b)
6768```
68696970Now the type tells the truth. This function returns either: