Skip to main content
This covers common TypeScript type-related errors in Sonamu and how to resolve them.

Reserved Keywords Collision

Symptoms

Runtime error:
Or during Sonamu sync:

Cause

Used JavaScript/TypeScript reserved keywords as method or property names.

Solution

Avoid using reserved keywords or use different names:
72 reserved keywords validated by Sonamu:

Type Inference Failure

Symptoms

Causes

  1. Sonamu syncer didn’t run properly
  2. .generated file is outdated
  3. TypeScript server cache issue

Solutions

1. Re-run Syncer

2. Restart TypeScript Server

VSCode:

3. Check Generated Files

If file is missing or outdated, re-run sync.

BaseModel Method Type Error

Symptoms

Cause

BaseModel’s auto-generated method types are not properly applied.

Solutions

1. Check entity.json

2. Check Model Class Definition

3. Regenerate Types with Syncer

Union Type Error

Symptoms

Type safety is not guaranteed.

Solution

Specify explicit type:

Zod Schema Type Mismatch

Symptoms

Cause

API method parameter type doesn’t match Zod schema.

Solutions

1. Fix Parameter Type

2. Use Explicit Zod Schema

Intersection Type Error

Symptoms

Solution

From Sonamu 0.7.29+, intersection/union types are automatically wrapped with parentheses:
Re-run sync after update:

Template Literal Type Error

Symptoms

Cause

Zod v4 changed how template literal types are handled.

Solution

Sonamu automatically handles backslash escaping:
Generated Zod schema:

Circular Reference Type Error

Symptoms

Cause

Two entities reference each other, causing circular dependency.

Solutions

1. Use Type-only Import

2. Create Common Types File

File Type Error (@upload)

Symptoms

Cause

The type of bufferedFiles?.[0] is BufferedFile | undefined, so accessing a property without a null check causes a type error.

Solution

Type Guard Error

Symptoms

Cause

Type guard function doesn’t perform type narrowing.

Solution

Use type predicate:

Generic Type Inference Failure

Symptoms

Solution

Specify explicit type:
Or type validation: