```typescript
/**
 * Perform topological sort on given nodes and edges.
 * @param nodes - Array of node names.
 * @param edges - Array of [from, to] pairs where from must come before to.
 * @returns An array representing a valid topological order.
 */
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
    const graph: { [key: string]: string[] } = {};
    const inDegree: { [key: string]: number } = {};

    // Initialize graph and in-degree count
    nodes.forEach(node => {
        graph[node] = [];
        inDegree[node] = 0;
    });

    // Build the graph and calculate in-degrees
    edges.forEach(([from, to]) => {
        if (!nodes.includes(from) || !nodes.includes(to)) {
            throw new Error(`Edge (${from}, ${to}) contains a node not in the input nodes.`);
        }
        graph[from].push(to);
        inDegree[to]++;
    });

    // Queue for nodes with zero in-degree
    const queue: string[] = Object.keys(inDegree).filter(node => inDegree[node] === 0);

    // Topological order result
    const result: string[] = [];

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

        graph[node].forEach(neighbor => {
            inDegree[neighbor]--;
            if (inDegree[neighbor] === 0) {
                queue.push(neighbor);
            }
        });
    }

    // Check for cycles
    if (result.length !== nodes.length) {
        throw new Error("Graph contains a cycle.");
    }

    return result;
}
```