```ts
/**
 * Computes the Levenshtein (edit) distance between two strings.
 * The edit distance is the minimum number of single-character insertions,
 * deletions, and substitutions required to transform one string into another.
 *
 * @param a - The first string.
 * @param b - The second string.
 * @returns The edit distance between the two strings.
 * @throws Error if either argument is not a string.
 */
export function editDistance(a: string, b: string): number {
  if (typeof a !== 'string' || typeof b !== 'string') {
    throw new Error('Both arguments must be strings');
  }

  const m = a.length;
  const n = b.length;

  // Create a DP table with dimensions (m+1) x (n+1)
  const dp: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));

  // Base cases: distance from empty string
  for (let i = 0; i <= m; i++) {
    dp[i][0] = i; // i deletions needed to turn first i chars of a into empty string
  }
  for (let j = 0; j <= n; j++) {
    dp[0][j] = j; // j insertions needed to turn empty string into b
  }

  // Fill the DP table
  for (let i = 1; i <= m; i++) {
    for (let j = 1; j <= n; j++) {
      if (a[i - 1] === b[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1]; // No operation needed
      } else {
        dp[i][j] = 1 + Math.min(
          dp[i - 1][j],    // Deletion
          dp[i][j - 1],    // Insertion
          dp[i - 1][j - 1] // Substitution
        );
      }
    }
  }

  return dp[m][n];
}
```