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

    for (const node of nodes) {
        graph.set(node, new Set());
        inDegree.set(node, 0);
    }

    for (const [from, to] of edges) {
        if (!graph.has(from)) throw new Error(`Node '${from}' is not in nodes.`);
        if (!graph.has(to)) throw new Error(`Node '${to}' is not in nodes.`);

        graph.get(from)?.add(to);
        inDegree.set(to, (inDegree.get(to) || 0) + 1);
    }

    const queue: string[] = [];
    for (const node of nodes) {
        if ((inDegree.get(node) || 0) === 0) {
            queue.push(node);
        }
    }

    const result: string[] = [];
    while (queue.length > 0) {
        if (queue.length !== 1) throw new Error('Cycle detected.');

        const node = queue.shift()!;
        result.push(node);

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

    return result;
}
```