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

  // Build the adjacency list and calculate indegrees
  for (const [from, to] of edges) {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error(`Edge references a non-existent node: ${to}`);
    }
    graph.set(from, (graph.get(from) || new Set<string>()).add(to));
    indegree.set(to, (indegree.get(to) || 0) + 1);
  }

  // Collect nodes with no dependencies
  const queue = [];
  for (const node of nodes) {
    if (!indegree.has(node)) {
      queue.push(node);
    }
  }

  const result: string[] = [];

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

    // Decrease the indegree of all adjacent nodes
    for (const neighbor of graph.get(node) || []) {
      indegree.set(neighbor, indegree.get(neighbor)! - 1);
      if (indegree.get(neighbor)! === 0) {
        queue.push(neighbor);
      }
    }
  }

  // Check if there is a cycle
  if (result.length !== nodes.length) {
    throw new Error("Cycle detected in the graph");
  }

  return result;
}
```