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

  // Initialize graph and in-degree count
  nodes.forEach(node => {
    graph[node] = [];
    inDegree[node] = 0;
  });

  // Build the graph and in-degree map
  edges.forEach(([from, to]) => {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error(`Invalid edge: ${from} -> ${to}`);
    }
    graph[from].push(to);
    inDegree[to]++;
  });

  // Initialize the queue with nodes having zero in-degree
  const queue: string[] = [];
  nodes.forEach(node => {
    if (inDegree[node] === 0) {
      queue.push(node);
    }
  });

  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);
      }
    });
  }

  // Check for cycles
  if (result.length !== nodes.length) {
    throw new Error("Cycle detected");
  }

  return result;
}
```