```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 graph and calculate indegrees
    for (const [from, to] of edges) {
        if (!graph.has(from)) {
            graph.set(from, new Set());
        }
        if (!graph.has(to)) {
            graph.set(to, new Set());
        }

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

    // Find all nodes with no dependencies
    const freeNodes = Array.from(indegree.keys()).filter(node => indegree.get(node) === 0);

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

        // Decrease the indegrees of all nodes that have an edge to 'node'
        for (const neighbor of graph.get(node) || []) {
            indegree.set(neighbor, (indegree.get(neighbor) || 0) - 1);
            if (indegree.get(neighbor)! === 0) {
                freeNodes.push(neighbor);
            }
        }
    }

    // Check if all nodes were processed
    if (result.length !== nodes.length) {
        throw new Error("Cycle detected in the graph");
    }

    return result;
}
```