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

  // Build the graph and calculate indegrees
  for (const [from, to] of edges) {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error("Edge names must be in nodes.");
    }
    graph.set(from, (graph.get(from) || new Set<string>()).add(to));
    indegree.set(to, (indegree.get(to) || 0) + 1);
  }

  // Initialize the queue with nodes that have no dependencies
  const queue: string[] = [];
  for (const node of nodes) {
    if (!indegree.has(node)) {
      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 in the graph.");
  }

  return result;
}
```