FOMO Daily
Feed
Evil Martians·

How to make postMessage type-safe in under 350 bytes

Frontend & WebTypeScriptpostMessageWeb WorkersType Safety

TL;DR

Browser messaging with postMessage requires repetitive routing, cleanup, and reply-handling code, while leaving message names and payloads unchecked. Evil Martians’ typed-channel uses shared TypeScript message definitions and interchangeable transports to provide one checked API across workers, iframes, tabs, and in-page events. The core plus postMessage transport weighs just 341 bytes compressed, while optional request/response support adds typed replies and cancellation that reaches the receiving handler.

Relevant links

Sign in to save links
Read the original post Sign in to mark as read or skip