```ts
/**
 * Calculates the Levenshtein edit distance between two strings.
 * The minimum number of single-character insertions, deletions, and substitutions
 * required to transform string `a` into string `b`.
 * 
 * @param a - The source string.
 * @param b - The target 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 DP table with dimensions (m+1) x (n+1)
  const dp: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));

  // Initialize base cases
  // Distance from empty string to b[0..i-1] is i
  for (let i = 0; i <= m; i++) {
    dp[i][0] = i;
  }
  
  // Distance from a[0..j-1] to empty string is j
  for (let j = 0; j <= n; j++) {
    dp[0][j] = j;
  }

  // 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]) {
        // Characters match, no operation needed
        dp[i][j] = dp[i - 1][j - 1];
      } else {
        // Take minimum of three operations:
        // 1. Insert: dp[i][j-1] + 1
        // 2. Delete: dp[i-1][j] + 1
        // 3. Replace: dp[i-1][j-1] + 1
        dp[i][j] = Math.min(
          dp[i][j - 1] + 1,    // Insert
          dp[i - 1][j] + 1,    // Delete
          dp[i - 1][j - 1] + 1 // Replace
        );
      }
    }
  }

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