```typescript
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  const graph = new Map<string, Set<string>>();

  // Build the graph
  for (const [from, to] of edges) {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error("Edge names must be in nodes");
    }
    if (!graph.has(from)) {
      graph.set(from, new Set());
    }
    graph.get(from)?.add(to);
  }

  const indegree = new Map<string, number>();
  for (const node of nodes) {
    indegree.set(node, 0);
  }

  // Calculate the indegree of each node
  for (const [from, to] of edges) {
    indegree.set(to, (indegree.get(to) || 0) + 1);
  }

  const queue: string[] = [];
  for (const node of nodes) {
    if (indegree.get(node) === 0) {
      queue.push(node);
    }
  }

  const result: string[] = [];

  while (queue.length > 0) {
    const node = queue.shift()!;
    result.push(node);

    // Decrease the indegree of all neighbors
    for (const neighbor of graph.get(node) || []) {
      indegree.set(neighbor, (indegree.get(neighbor)! - 1));
      if (indegree.get(neighbor)! === 0) {
        queue.push(neighbor);
      }
    }
  }

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

  return result;
}
```