```ts
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>();

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

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

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

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

    const result: string[] = [];

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

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

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

    return result;
}
```