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

  // Build the graph and calculate indegrees
  for (const [from, to] of edges) {
    if (!graph.has(from)) graph.set(from, new Set());
    if (!graph.has(to)) graph.set(to, new Set());

    graph.get(from)?.add(to);
    indegreeMap.set(to, (indegreeMap.get(to) || 0) + 1);
  }

  // Queue for nodes with no incoming edges
  const queue: string[] = [];
  for (const [node] of graph.entries()) {
    if (!indegreeMap.has(node)) queue.push(node);
  }

  const result: string[] = [];

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

    for (const neighbor of graph.get(node) || new Set()) {
      indegreeMap.set(neighbor, indegreeMap.get(neighbor)! - 1);
      if (indegreeMap.get(neighbor)! === 0) queue.push(neighbor); // Add to queue if no incoming edges
    }
  }

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

  return result;
}
```