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

    // Build the graph and indegree map
    for (const [from, to] of edges) {
        if (!nodes.includes(from) || !nodes.includes(to)) {
            throw new Error(`Edge names must be in nodes: ${from} -> ${to}`);
        }
        graph.set(from, (graph.get(from) || new Set()).add(to));
        indegree.set(to, (indegree.get(to) || 0) + 1);
    }

    // Initialize the queue with nodes that have no dependencies
    const queue = Array.from(nodes).filter(node => !indegree.has(node));

    const result: string[] = [];

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

        // Decrease the indegree of all neighbors and add them to the queue if they have no more dependencies
        for (const neighbor of graph.get(currentNode) || []) {
            indegree.set(neighbor, indegree.get(neighbor)! - 1);
            if (indegree.get(neighbor) === 0) {
                queue.push(neighbor);
            }
        }
    }

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

    return result;
}
```