```ts
/**
 * Merge overlapping intervals in a list of start-end pairs.
 *
 * This function takes a list of [start, end] pairs, merges any that overlap,
 * and returns the smallest list of non-overlapping pairs covering the same points,
 * sorted ascending by start. Intervals that merely touch (end === next start) do merge.
 *
 * The function is pure: it does not mutate the input array nor any of its inner arrays,
 * and every returned pair is a fresh array.
 */
export function mergeIntervals(intervals: number[][]): number[][] {
    // Check for invalid input
    if (!intervals.every(interval => interval.length === 2 && typeof interval[0] === 'number' && typeof interval[1] === 'number')) {
        throw new Error('Invalid input');
    }

    // Sort the intervals by start value
    const sortedIntervals = intervals.slice().sort((a, b) => a[0] - b[0]);

    // Initialize the result with the first interval, if it's valid
    const merged: number[][][] = [sortedIntervals[0]];
    for (const current of sortedIntervals.slice(1)) {
        // If this is not the first interval and its start value is before the end value of the last merged interval,
        // merge them by updating the end value of the last merged interval
        if (current[0] <= merged[merged.length - 1][1]) {
            merged[merged.length - 1] = [merged[merged.length - 1][0], Math.max(merged[merged.length - 1][1], current[1])];
        } else {
            // Otherwise, add the next interval to the result
            merged.push(current);
        }
    }

    return merged;
}
```