```ts
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  const graph = new Map<string, Set<string>>();
  const inDegrees = new Map<string, number>();
  nodes.forEach(node => {
    graph.set(node, new Set());
    inDegrees.set(node, 0);
  });
  
  for (const [from, to] of edges) {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error(`Edge (${from}, ${to}) mentions a node not in nodes`);
    }
    graph.get(from)!.add(to);
    inDegrees.set(to, inDegrees.get(to)! + 1);
  }

  const queue: string[] = [];
  nodes.forEach(node => {
    if (inDegrees.get(node)! === 0) {
      queue.push(node);
    }
  });

  const result: string[] = [];
  while (queue.length > 0) {
    const node = queue.shift()!;
    result.push(node);

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

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

  return result;
}
```