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

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

  edges.forEach(([from, to]) => {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error(`Edge contains a node not in the nodes list: ${from} -> ${to}`);
    }
    graph[from].add(to);
    inDegree[to]++;
  });

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

  const result: string[] = [];

  while (queue.length > 0) {
    const node = queue.shift()!;
    result.push(node);
    graph[node].forEach(neighbor => {
      inDegree[neighbor]--;
      if (inDegree[neighbor] === 0) {
        queue.push(neighbor);
      }
    });
  }

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

  return result;
}
```