Published: May 5, 2025
1
14
49

🚀 I recently released typed-channel—a tiny library for building type-safe communication between different parts of your apps! Check out this demo of type-safe worker communication in action ⬇️

Want to play with the code yourself? Try the interactive demo: And, of course, you can install the package itself: npm install typed-channel

What makes typed-channel special? The transports system! It provides EventTarget and PostMessage transports (which covers a lot of web APIs) out of the box, plus you can create custom transports for any messaging system.

When might you need typed-channel? • Event buses • Web Workers communication • Communication between tabs (BroadcastChannel) • Any event-based system where you want payload type checking And it is with zero dependencies and small bundle size! 📦

typed-channel was born out of a real need in our Harmonizer project where we wanted to communicate with Web Workers in a type-safe way. No more guessing what messages are available or what payload shape to expect—the compiler keeps everything in check!

After the worker implementation, I needed a type-safe event bus system. I realized the pattern was similar—just with different message transfer methods. This insight led to the "transports" concept—swappable communication mechanisms that all share the same type-safe API.

typed-channel proved its worth when we started developing Figma plugin, where main and ui threads are separate ones. I just created a custom transport implementation and got full type safety between the plugin and UI contexts, as I had with Worker and events bus before!

No more message passing with unknown payloads! You can find docs & examples in the repository. Star it if it helps you! ⭐

Share this thread

Read on Twitter

View original thread

Navigate thread

1/8