TypeScript

The Web SDK ships with TypeScript types. Prefer explicit message schemas and narrow payload parsing for safety.

Strongly-typed envelopes

type ChatEnvelope = {
  v: 1;
  type: 'chat.message';
  room: string;
  id: string;
  ts: number;
  body: string;
};

function decodeChat(bytes: Uint8Array): ChatEnvelope {
  const text = new TextDecoder().decode(bytes);
  const obj = JSON.parse(text);
  // validate fields here
  return obj as ChatEnvelope;
}

Recommended config

  • Enable noUncheckedIndexedAccess for safer parsing.
  • Prefer runtime validation for untrusted data.