```ts
function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
    if (nodes.length === 0) return [];

    const adjList = new Map<string, Set<string>>(nodes.map((node) => [node, new Set()]));
    for (const [from, to] of edges) {
        adjList.get(from)?.add(to);
    }

    const inDegree = new Map<string, number>();
    for (const node of nodes) {
        inDegree.set(node, 0);
    }
    for (const [from, to] of edges) {
        inDegree.set(to, inDegree.get(to)! + 1);
    }

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

    const ordering: string[] = [];
    while (queue.length > 0) {
        const node = queue.shift()!;
        ordering.push(node);

        if (!adjList.has(node)) continue;

        for (const neighbour of adjList.get(node)!) {
            inDegree.set(neighbour, inDegree.get(neighbour)! - 1);
            if (inDegree.get(neighbour) === 0 && !queue.includes(neighbour)) {
                queue.push(neighbour);
            }
        }
    }

    if (ordering.length !== nodes.length) {
        throw new Error('Cycle detected: a node has an in-degree of more than zero after processing all edges.');
    }

    const nodeToNodeMap = new Map<string, string>();
    for (const [from, to] of edges) {
        nodeToNodeMap.set(from, to);
    }

    if (!ordering.every((node) => !inDegree.has(node))) {
        throw new Error(`Invalid edge "${ ordering[0] }" in ${ nodes }.`);
    }

    return ordering;
}
```