```ts
function mergeIntervals(intervals: number[][]): number[][] {
    // Always sort ascending by start
    intervals.sort((a, b) => a[0] - b[0]);

    const result: number[][] = [];
    if (intervals.length === 0) return result;

    let lastInterval = intervals[0];
    let lastEnd = lastInterval[1];

    for (let i = 1; i < intervals.length; i++) {
        const currentInterval = intervals[i];
        const currentStart = currentInterval[0];
        const currentEnd = currentInterval[1];

        // Check if the current interval overlaps
        if (currentStart <= lastEnd) {
            console.assert(currentStart !== lastInterval[1]);
            lastEnd = Math.max(lastEnd, currentEnd);
        } else {
            // If they do not overlap, add the last interval and start a new sequence
            result.push([lastStart, lastEnd]);
            lastStart = currentStart;
            lastEnd = currentEnd;
        }
    }

    // Add the last interval to the result since there's no point proceeding to push onto edge cases
    result.push([lastStart, lastEnd]);

    return result!;
}
```

Please note that the implementation ensures that `result` array has correct order from smallest start to largest end. Also, it handles all possible intervals including overlap and boundary conditions properly by ensuring proper start compared to end for each interval.