```typescript
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  const graph: Record<string, Set<string>> = {};
  const inDegree: Record<string, number> = {};

  nodes.forEach(node => {
    graph[node] = new Set();
    inDegree[node] = 0;
  });

  for (const [from, to] of edges) {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error(`Edge uses a node not in nodes: ${from} -> ${to}`);
    }
    graph[from].add(to);
    inDegree[to]++;
  }

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

  let sortedNodes: string[] = [];
  while (queue.length > 0) {
    if (sortedNodes.length !== nodes.length) {
      throw new Error('Cycle detected');
    }
    const node = queue.shift()!;
    sortedNodes.push(node);
    for (const neighbor of graph[node]) {
      inDegree[neighbor]--;
      if (inDegree[neighbor] === 0) {
        queue.push(neighbor);
      }
    }
  }

  return sortedNodes;
}
```