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.- HasMany, ManyToMany Relations are excluded
- BelongsToOne, OneToOne(hasJoinColumn) are included as
{name}_idformat - Virtual fields only have type definition, values are computed in Enhancer
Subset Types
Types that include only partial fields of the Entity.ListParams Types
Parameter types for list query APIs.zArrayable: A helper that allows both single values and arrays.
SaveParams Types
Parameter types for save APIs.- Only
idis optional, other fields are required - With
id→ UPDATE, without → INSERT - Can save multiple records simultaneously with array
Enum Types
Entity Enums are auto-generated.Custom Params Types
Define custom parameter types when creating additional APIs in Model.Action Params Types
Parameter types for specific actions.ListResult Type
Type for list query results.sonamu.shared.ts
Conditional types:
ListResult uses TypeScript conditional types to return different types
based on queryMode.Type Exports
Generated types are automatically exported.sonamu.generated.ts
Type Utilities
Useful type utilities provided by Sonamu.zArrayable
Type that allows both single values and arrays.DistributiveOmit
Safer than regularOmit 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