```ts
export function splitLength(mm: number): string {
  if (!Number.isInteger(mm) || mm < 0) {
    throw new Error("Invalid length");
  }

  const m = Math.floor(mm / 1000);
  const cm = Math.floor((mm % 1000) / 10);
  const mmPart = mm % 10;

  let result: string[] = [];

  if (m > 0) {
    result.push(`${m}m`);
  }
  if (cm > 0 || result.length === 0) {
    result.push(`${cm}cm`);
  }
  if (mmPart > 0 || result.length === 0) {
    result.push(`${mmPart}mm`);
  }

  return result.join(" ");
}
```