← Effect fixes your TypeScript

Effect fixes your TypeScript · Part 3

If you can write async/await, you can write Effect

· by Tony Tang

async function becomes Effect.fn. await becomes yield*. Same lines, same order. Only the type changes: now it says how the function fails and what it needs.

Comment below: Which version do you read faster?

Effect fixes your TypeScript: a series on the bugs you already ship, and how Effect makes them impossible. All code is real Effect v4 and was compiled before it went on screen. https://effect.website

Transcript

If you can write async/await, you can already write Effect. Here's getUser with async/await. Await the database, check the result, return the user. Then people see Effect and think monads, pipes, a whole new language. That fear is what stops most teams from trying it. Now watch the same function turn into Effect. Async function becomes Effect.fn. Await becomes yield*. That's it. Same lines, same order. If, loops, early returns, all still work. The only real difference is the type. Now it tells you how it fails and what it needs. Best practice, write Effect like normal code. Use pipe when it reads better, not to look clever. So the database is down. Let's retry it properly. Part four, which version do you read faster?

Full lesson in the Learn Effect course ↗ Effect.gen, sequence effects like async/await

More from this series