Skip to main content
Sonamu automatically generates various types from Entity definitions. Not only base types, but also API parameters, Subset types, Enums, and more are auto-generated to provide complete type safety.

Generated Types Overview

Base Types

Entity’s basic types: User, Post, Comment

Subset Types

Partial query types: UserA, UserP, UserSS

Params Types

API parameter types: ListParams, SaveParams

Enum Types

Enums and helper functions: UserRole, userRoleLabel

Base Types

Basic types including all fields of the Entity.
Characteristics:
  • HasMany, ManyToMany Relations are excluded
  • BelongsToOne, OneToOne(hasJoinColumn) are included as {name}_id format
  • Virtual fields only have type definition, values are computed in Enhancer

Subset Types

Types that include only partial fields of the Entity.
Usage example:

ListParams Types

Parameter types for list query APIs.
Usage example:
zArrayable: A helper that allows both single values and arrays.

SaveParams Types

Parameter types for save APIs.
Characteristics:
  • Only id is optional, other fields are required
  • With id → UPDATE, without → INSERT
  • Can save multiple records simultaneously with array

Enum Types

Entity Enums are auto-generated.
Usage example:

Custom Params Types

Define custom parameter types when creating additional APIs in Model.
Auto-generated:

Action Params Types

Parameter types for specific actions.

ListResult Type

Type for list query results.
sonamu.shared.ts
Usage example:
Conditional types: ListResult uses TypeScript conditional types to return different types based on queryMode.

Type Exports

Generated types are automatically exported.
sonamu.generated.ts
Usage:

Type Utilities

Useful type utilities provided by Sonamu.

zArrayable

Type that allows both single values and arrays.

DistributiveOmit

Safer than regular Omit for Union types.

Customizing Type Generation

You can extend or modify auto-generated types.

Extending Params

user.types.ts

Extending Subset Types

user.types.ts

Creating Conditional Types

user.types.ts

Practical Example

Example of using generated types in a real project.

Next Steps

E2E Type Safety

Understanding end-to-end type safety

Zod Validation

Runtime validation with Zod

Entity Types

Entity type conversion in detail

Model

Using types in Model