```ts
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  const graph: { [node: string]: string[] } = {};
  const inDegree: { [node: string]: number } = {};
  nodes.forEach(node => {
    graph[node] = [];
    inDegree[node] = 0;
  });

  for (const [from, to] of edges) {
    if (!nodes.includes(from)) throw new Error(`Node "${from}" not found.`);
    if (!nodes.includes(to)) throw new Error(`Node "${to}" not found.`);
    graph[from].push(to);
    inDegree[to]++;
  }

  const queue: string[] = nodes.filter(node => inDegree[node] === 0);

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

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