```ts
export function romanToInt(input: string): number {
  if (typeof input !== 'string') {
    throw new Error('Input must be a string');
  }
  
  if (input.length === 0) {
    throw new Error('Input cannot be empty');
  }
  
  const romanChars = new Set(['I', 'V', 'X', 'L', 'C', 'D', 'M']);
  for (const char of input) {
    if (!romanChars.has(char)) {
      throw new Error('Invalid character in input');
    }
  }
  
  const romanValues: { [key: string]: number } = {
    'I': 1,
    'V': 5,
    'X': 10,
    'L': 50,
    'C': 100,
    'D': 500,
    'M': 1000
  };
  
  let value = 0;
  for (let i = 0; i < input.length; i++) {
    const current = romanValues[input[i]];
    const next = i + 1 < input.length ? romanValues[input[i + 1]] : 0;
    
    if (current < next) {
      value += next - current;
      i++; // Skip the next character since we've already processed it
    } else {
      value += current;
    }
  }
  
  if (value <= 0 || value > 3999) {
    throw new Error('Value out of range');
  }
  
  // Re-encode the computed value canonically to verify it matches input
  const canonical = intToRoman(value);
  if (canonical !== input) {
    throw new Error('Input is not canonical');
  }
  
  return value;
}

function intToRoman(num: number): string {
  if (num <= 0 || num > 3999) {
    throw new Error('Number out of range');
  }
  
  const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
  const symbols = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
  
  let result = '';
  for (let i = 0; i < values.length; i++) {
    while (num >= values[i]) {
      result += symbols[i];
      num -= values[i];
    }
  }
  
  return result;
}
```