```ts
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
    const graph: { [key: string]: string[] } = {};
    const inDegree: { [key: string]: number } = {};

    for (const node of nodes) {
        graph[node] = [];
        inDegree[node] = 0;
    }

    for (const [from, to] of edges) {
        if (!nodes.includes(from) || !nodes.includes(to)) {
            throw new Error(`Edge ${from} -> ${to} includes a node not in nodes`);
        }
        graph[from].push(to);
        inDegree[to]++;
    }

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

    const result: string[] = [];

    while (queue.length > 0) {
        if (queue.length !== 1) {
            throw new Error("Cycle detected");
        }
        const node = queue.shift()!;
        result.push(node);

        for (const neighbor of graph[node]) {
            inDegree[neighbor]--;
            if (inDegree[neighbor] === 0) {
                queue.push(neighbor);
            }
        }
    }

    return result;
}
```