```ts
const LADDER: [string, number][] = [["m", 1000], ["cm", 10], ["mm", 1]];

export function splitLength(mm: number): string {
  // Validate mm: must be a whole number and non-negative.
  if (!Number.isInteger(mm) || mm < 0) {
    throw new Error("Invalid length. Must be a whole non-negative number.");
  }

  let result: [string, number][] = [];
  for (const [unit, scale] of LADDER) {
    const count = Math.floor(mm / scale);
    if (count > 0) {
      result.push([unit, count]);
      mm %= scale;
    }
  }

  // Join the result array into a string in the desired format.
  return result.map(([unit, count]) => `${count}${unit}`).join(" ");
}
```