Skip to main content
Learn how Sonamu detects API changes at compile time to prevent runtime errors in advance.

Compile-time Errors Overview

Instant Detection

On API changes Compile-time errors

Runtime Safety

Discover before deploy Production stability

IDE Integration

Red underlines Immediate feedback

Safe Refactoring

Large-scale changes Impact range visibility

What are Compile-time Errors?

Problem: Errors Only Discovered at Runtime

In traditional development, API changes are only discovered at runtime.
Problems with runtime errors:
  1. Occurs in production: Users experience directly
  2. Delayed discovery: Only discovered via QA or user reports
  3. Hard to debug: Need to trace where problem occurred
  4. Trust degradation: Service stability decreases

Solution: Compile-time Errors

Sonamu detects API changes immediately at compile time.
Benefits of compile-time errors:
  1. ✨ Instant discovery: IDE shows immediately while coding
  2. ✨ Fix before deploy: Resolve all issues before production deploy
  3. ✨ Impact range visibility: See all places affected by change
  4. ✨ Auto refactoring: Use IDE’s Rename feature

Error Detection Scenarios

1. Field Name Change

IDE error message:

2. Field Type Change

IDE error message:

3. Required/Optional Change

IDE error message:
Fix:

4. Field Deletion

5. Parameter Change

IDE error message:

6. Return Type Change

Fix:

Refactoring Support

Large-scale Changes are Safe

You can immediately identify all locations affected by API changes.
After running pnpm generate: All error locations are displayed in IDE:
Fix process:
  1. Check all errors in IDE’s β€œProblems” panel
  2. Visit each location and fix to match new structure
  3. When all errors are resolved, compilation succeeds
  4. Deploy safely

Leverage IDE’s Auto Refactoring

You can utilize TypeScript’s powerful refactoring features. Example: Batch Field Name Change
  1. Check type definition in Service file
  2. Position cursor on field name
  3. F2 (Rename Symbol) or right-click β†’ Rename
  4. Enter new name
  5. All usages are automatically changed

Practical Workflow

1. Backend API Change

2. Service Regeneration

Output:

3. TypeScript Compile

Output (error occurs):

4. Fix Errors

5. Re-verify

Output (success):

6. Deploy Safely

All type errors are resolved, so you can deploy safely.

CI/CD Integration

Add TypeScript Check to CI

Benefits:
  • Auto-detect type errors in Pull Requests
  • Block merge if type errors exist
  • Ensure code quality across the team

Best Practices

1. Regular Service Regeneration

2. Pre-commit Hook Setup

Blocks commit if type errors exist.

3. VSCode Settings

4. Don’t Ignore Type Errors

Never use @ts-ignore. Type errors indicate real problems.

Understanding Error Messages

Common Error Messages

1. Property does not exist
β†’ Field was deleted or renamed 2. Type is not assignable
β†’ Type was changed 3. Object is possibly undefined
β†’ Changed from required to optional 4. Cannot find name
β†’ Service not regenerated or import missing 5. Expected N arguments, but got M
β†’ API parameters added/removed

Cautions

Cautions when handling compile-time errors: 1. pnpm generate required: Always run after API changes 2. No @ts-ignore: Don’t ignore type errors 3. No any type: Breaks type safety 4. Fix all errors: Even one left can cause runtime error 5. CI/CD integration: Set up auto type checking

Next Steps

API Type Inference

Understanding type inference

Shared Types

Type file structure

Using Services

Service usage

Testing

Writing tests