```ts
export function topologicalSort(
  nodes: readonly string[],
  edges: readonly (readonly [string, string])
): string[] {
  const graph: Record<string, string[]> = {};
  const inDegree: Record<string, number> = {};
  for (const node of nodes) {
    graph[node] = [];
  }

  for (const [from, to] of edges) {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error(`Unknown node in edge: ${from} -> ${to}`);
    }
    graph[from].push(to);
    inDegree[to] = (inDegree[to] ?? 0) + 1;
  }

  const queue: string[] = [];
  for (const node of nodes) {
    if (!inDegree[node]) {
      queue.push(node);
    }
  }

  const result: string[] = [];
  while (queue.length > 0) {
    const current = queue.shift()!;
    result.push(current);

    for (const neighbor of graph[current]) {
      inDegree[neighbor]--;
      if (inDegree[neighbor] === 0) {
        queue.push(neighbor);
      }
    }
  }

  if (result.length !== nodes.length) {
    throw new Error("Cycle detected");
  }

  return result;
}
```