```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);
    }

    // Initialize the queue with nodes that have no incoming edges
    const queue: string[] = [];
    for (const node of nodes) {
        if (!indegree.has(node)) queue.push(node);
    }

    const result: string[] = [];

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

        // Decrease the indegree of all neighbors
        for (const neighbor of graph.get(current) || []) {
            indegree.set(neighbor, indegree.get(neighbor)! - 1);
            if (indegree.get(neighbor)! === 0) {
                queue.push(neighbor);
            }
        }
    }

    // Check for cycles
    if (result.length !== nodes.length) {
        throw new Error("Cycle detected");
    }

    return result;
}
```