```ts
export function expandGlossary(script: string[]): string {
  if (!Array.isArray(script)) {
    throw new Error("Script is not a list.");
  }

  const slots: Record<string, string> = {};
  const sent: string[] = [];

  for (const line of script) {
    if (typeof line !== "string") {
      throw new Error("Line is not a string.");
    }

    if (line.startsWith("!")) {
      const slotNumber = line.slice(1);
      if (!slotNumber || !/^\d+$/.test(slotNumber) || parseInt(slotNumber, 10) <= 0) {
        throw new Error("Invalid slot number in send line.");
      }
      sent.push(slots[slotNumber] ?? "");
    } else if (line.includes("=")) {
      const cut = line.indexOf("=");
      const slotNumber = line.slice(0, cut);
      const body = line.slice(cut + 1);

      if (!slotNumber || !/^\d+$/.test(slotNumber) || parseInt(slotNumber, 10) <= 0) {
        throw new Error("Invalid slot number in store line.");
      }
      if (slots[slotNumber] !== undefined) {
        throw new Error("Slot stored a second time.");
      }

      slots[slotNumber] = body.replace(/\{\{|\}\}/g, (match) => match === "{{" ? "{" : "}");
    } else {
      throw new Error("Line is of neither kind.");
    }
  }

  return sent
    .map((body) =>
      body.replace(/\{(\d+)\}/g, (_whole, n) => slots[n] ?? "")
    )
    .join("");
}
```