```typescript
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
    if (!nodes.length) return [];
    
    const adjacencyList = new Map<string, Set<string>>();
    const indegreeMap = new Map<string, number>();

    for (const node of nodes) {
        adjacencyList.set(node, new Set());
        indegreeMap.set(node, 0);
    }

    for (const [from, to] of edges) {
        if (!nodes.includes(from) || !nodes.includes(to)) {
            throw new Error('An edge names a node not in nodes.');
        }
        
        adjacencyList.get(from)?.add(to);
        indegreeMap.set(to, (indegreeMap.get(to) ?? 0) + 1);
    }

    const queue: string[] = [];
    for (const [node, degree] of indegreeMap.entries()) {
        if (degree === 0) {
            queue.push(node);
        }
    }

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

        for (const neighbor of adjacencyList.get(node)!) {
            indegreeMap.set(neighbor, indegreeMap.get(neighbor)! - 1);
            if (indegreeMap.get(neighbor)! === 0) {
                queue.push(neighbor);
            }
        }
    }

    return result.length !== nodes.length ? [] : result;
}
```