# How to make postMessage type-safe in under 350 bytes

DevFeed: [How to make postMessage type-safe in under 350 bytes](<https://devfeed.tech/articles/how-to-make-postmessage-type-safe-in-under-350-bytes-105920.md>)

Original publisher: [Read original article](<https://evilmartians.com/chronicles/how-to-make-postmessage-type-safe-in-under-350-bytes>)

Author: Travis Turner (richardturner@evilmartians.com)

Published: 2026-10-28T00:00:00Z

Content type: article

Language: en

Sources: [Evil Martians](<https://devfeed.tech/sources/evil-martians.md>)

Topics: [Messaging](<https://devfeed.tech/topics/messaging.md>), [Publish-subscribe pattern](<https://devfeed.tech/topics/pubsub.md>), [union types](<https://devfeed.tech/topics/union-types.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [boilerplate](<https://devfeed.tech/tags/boilerplate.md>), [brotli](<https://devfeed.tech/tags/brotli.md>), [bus](<https://devfeed.tech/tags/bus.md>), [cancellation](<https://devfeed.tech/tags/cancellation.md>), [channel](<https://devfeed.tech/tags/channel.md>), [cleanup](<https://devfeed.tech/tags/cleanup.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [dx](<https://devfeed.tech/tags/dx.md>), [errors](<https://devfeed.tech/tags/errors.md>), [events](<https://devfeed.tech/tags/events.md>), [iframes](<https://devfeed.tech/tags/iframes.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [library](<https://devfeed.tech/tags/library.md>), [messages](<https://devfeed.tech/tags/messages.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [postmessage](<https://devfeed.tech/tags/postmessage.md>), [type-safe](<https://devfeed.tech/tags/type-safe.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [workers](<https://devfeed.tech/tags/workers.md>)

## AI overview

typed-channel gives TypeScript-checked message names and payloads across workers, iframes, tabs, and in-page event buses, using a shared channel API with interchangeable transports. Its `on` method returns an unsubscribe function; custom transports need only `on` and `emit`. The excerpt reports a 341-byte core with the `postMessage` transport and no dependencies. Version 0.11 adds optional RPC through `createTypedRpcChannel`: typed requests and handlers, propagated errors, and `AbortSignal` cancellation that stops handler work. Requests without a matching handler do not resolve on their own, so callers should provide a timeout signal when needed. Payloads and results are structured-cloned without library validation. `unlisten()` disconnects transports and rejects pending requests while aborting corresponding remote work. The RPC factory is about 1 kB; one-way messaging remains separate so projects pay for RPC only when used.

## Source excerpt

Typed-channel is a library for typed messages and requests across workers, iframes, tabs, and event buses.