```ts
import { Graph } from 'simple-graph-js';

export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  const graph = new Graph();

  for (const edge of edges) {
    if (!graph.hasNode(edge[0])) {
      graph.addNode(edge[0]);
    }
    if (!graph.hasNode(edge[1])) {
      graph.addNode(edge[1]);
    }
    graph.addEdge(edge[0], edge[1]);
  }

  const nodeCounts = new Map(nodes.map(node => [node, 0]));

  for (const [from, to] of edges) {
    nodeCounts.set(to, nodeCounts.get(to)! + 1);
  }

  const queue: string[] = [];

  for (const node of nodes) {
    if (nodeCounts.get(node)! === 0) {
      queue.push(node);
    }
  }

  const sortedNodes: string[] = [];

  while (queue.length > 0) {
    const current = queue.shift()!;
    sortedNodes.push(current);

    const neighbors = graph.neighbors(current);

    for (const neighbor of neighbors) {
      nodeCounts.set(neighbor, nodeCounts.get(neighbor)! - 1);
      if (nodeCounts.get(neighbor)! === 0) {
        queue.push(neighbor);
      }
    }
  }

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

  return sortedNodes;
}
```