```typescript
export function mergeIntervals(intervals: number[][]): number[][] {
  if (!Array.isArray(intervals) || !intervals.length) {
    throw new Error("Input must be a non-empty array of intervals");
  }

  for (const interval of intervals) {
    if (!Array.isArray(interval) || interval.length !== 2) {
      throw new Error("Each interval must be an array with exactly two elements");
    }
    const [start, end] = interval;
    if (typeof start !== "number" || typeof end !== "number") {
      throw new Error("Start and end of each interval must be numbers");
    }
    if (start > end) {
      throw new Error("Interval start cannot be greater than its end");
    }
  }

  intervals.sort((a, b) => a[0] - b[0]);

  const mergedIntervals: number[][] = [];
  let currentInterval = intervals[0];

  for (let i = 1; i < intervals.length; i++) {
    const [start, end] = intervals[i];
    if (end >= currentInterval[0]) {
      // Merge the intervals
      currentInterval[1] = Math.max(currentInterval[1], end);
    } else {
      // Add the current interval to the merged list and update currentInterval
      mergedIntervals.push([...currentInterval]);
      currentInterval = [start, end];
    }
  }

  // Add the last interval
  mergedIntervals.push([...currentInterval]);

  return mergedIntervals;
}
```