```ts
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  if (!nodes.length) return [];

  const graph = new Map<string, Set<string>>();
  const indegree = new Map<string, number>();

  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);
    indegree.set(to, (indegree.get(to) || 0) + 1);
  }

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

  const result: string[] = [];

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

    for (const neighbor of graph.get(currentNode) || []) {
      indegree.set(neighbor, indegree.get(neighbor)! - 1);
      if (indegree.get(neighbor)! === 0) {
        queue.push(neighbor);
      }
    }
  }

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

  return result;
}
```