# `AshTypescript.TypedChannel.PayloadFormatter`
[🔗](https://github.com/ash-project/ash_typescript/blob/v0.18.1/lib/ash_typescript/typed_channel/payload_formatter.ex#L5)

Formats typed channel payloads at the websocket boundary.

Ash PubSub broadcasts carry the publication's `transform` result verbatim
(snake_case atom keys), while the generated TypeScript payload types use the
configured `output_field_formatter` — so without intervention the types would
not match the wire for multi-word fields.

The interception code injected by `use AshTypescript.TypedChannel` (see
`AshTypescript.TypedChannel.Interception`) routes intercepted events through
this module, which formats the payload with the same type-driven
`ValueFormatter` the RPC pipeline uses before pushing to the client.

# `format_payload`

```elixir
@spec format_payload(module(), String.t(), term()) :: term()
```

Formats a broadcast payload for the client using the publication's `returns`
type and the configured `output_field_formatter`.

Returns the payload unchanged when the resource has no publication matching
`event` or the publication declares no `returns` type.

# `push_formatted`

```elixir
@spec push_formatted(Phoenix.Socket.t(), module(), String.t(), term()) :: :ok
```

Formats `payload` according to the publication's `returns` type and pushes
it to the socket under `event`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
