← Back to Demo Hub
Test #16Data Handling

Type Coercion Error

Calling string methods on numbers or vice versa without type checking.

📋 Demo Instructions

  1. Click the "Trigger Error" button below
  2. Open browser console (F12) to see the error
  3. Wait 5-10 seconds for the error to be captured
  4. Go to Dashboard → Performance Monitoring
  5. Click "Fix with Carla" on the error
  6. Review the generated PR
🌍 Real-World Scenario
API changes field type from string to number (or vice versa) without frontend being notified. Common with IDs, phone numbers, or zip codes that were strings but backend changed to integers for database optimization.
✅ Expected Fix
Add type conversion (String() or Number()) before using type-specific methods, or add runtime type checking.
Fix Confidence:HIGH

💻 Buggy Code

// Buggy Code
const user = await fetchUser();
const paddedId = user.id.padStart(8, '0');
// TypeError: user.id.padStart is not a function

// Expected: id as string "12345"
// Got: id as number 12345

🔴 Error Log

Waiting for error to be triggered...