```ts
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  const nodeIndex = new Map<string, number>();
  nodes.forEach((node, index) => nodeIndex.set(node, index));

  const adjacencyList: { [key: string]: string[] } = {};
  const inDegree: { [key: string]: number } = {};

  // Initialize adjacency list and in-degree map
  nodes.forEach(node => {
    adjacencyList[node] = [];
    inDegree[node] = 0;
  });

  for (const [from, to] of edges) {
    if (!nodeIndex.has(from) || !nodeIndex.has(to)) {
      throw new Error(`Edge references non-existent node: (${from}, ${to})`);
    }
    adjacencyList[from].push(to);
    inDegree[to]++;
  }

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

  const sortedOrder: string[] = [];

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

    for (const neighbor of adjacencyList[node]) {
      inDegree[neighbor]--;
      if (inDegree[neighbor] === 0) {
        queue.push(neighbor);
      }
    }
  }

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

  return sortedOrder;
}
```