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

    nodes.forEach(node => {
        graph[node] = [];
        inDegree[node] = 0;
    });

    for (const [from, to] of edges) {
        if (!nodes.includes(from)) throw new Error(`Node ${from} not found in nodes`);
        if (!nodes.includes(to)) throw new Error(`Node ${to} not found in nodes`);
        graph[from].push(to);
        inDegree[to]++;
    }

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

    const result: string[] = [];

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

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

    if (result.length !== nodes.length) {
        throw new Error('Cycle detected in the graph');
    }

    return result;
}
```