services.generated.ts generated by Sonamu and how to use it.
Shared Types Overview
Single File
services.generated.ts All types in one place
Auto Generated
Extracted from backend No manual work needed
Type Reuse
Exported types Use throughout project
Consistency
Single source of truth No type conflicts
services.generated.ts Structure
File Overview
Sonamu generates all types and Services in a single file.- Usually 1,000 ~ 5,000 lines
- Can be 10,000+ lines with many Entities and APIs
- But all auto-generated so no management burden
Type Categories
1. Entity Types
Represents database table structure.- Exactly same as backend Entity
- All field types accurately mapped
- null, undefined, union types all preserved
2. Subset Types
Defines subsets of Entity.- A: Minimum fields (id + 1~2 core fields)
- B: Medium fields (A + additional info)
- C: All fields
3. API Parameter Types
Defines API function parameters.4. API Response Types
Defines API function return types.5. TanStack Query Related Types
Types used in React Hooks.Type Reuse
Using Type Helpers
Reuse existing types with TypeScriptβs utility types.Component Props
Use generated types as Props.Form Data Types
Use API parameter types as form data.State Management
Reuse types in global state as well.Namespace Usage
Service Grouping
Services are grouped by Entity using Namespace.- Prevents name collisions (getUser vs getPost)
- Related functions logically grouped
- Imports become concise
- IDE auto-completion becomes more accurate
Type Import
Usetype keyword when importing types only.
import typeis removed after compilation- Bundle size optimization
- Build speed improvement
File Size Management
Large-scale Projects
Files can become very large with many Entities and APIs.- β Auto-generated: No manual management needed
- β Tree-shaking: Unused code excluded from bundle
- β IDE performance: Modern IDEs handle large files fine
- β Type checking: TypeScript compiler processes efficiently
Code Splitting
You can split code with dynamic import if needed.Version Control
Include in Git or Not
Include (recommended):- Ready to use immediately after pull
- Can develop frontend without backend
- Can track type change history
- Less conflicts
- Each person generates latest version
- Git history stays clean
Resolving Conflicts
When merge conflict occurs:Debugging
Check Generated Types
You can check types directly in IDE.- VSCode:
Cmd + Click(Mac) /Ctrl + Click(Windows) - Jump directly to type definition
Debugging Type Errors
When type error occurs:- Check error message
- Check type definition
- Check backend
- Fix code
Cautions
Next Steps
API Type Inference
Understanding type inference
Compile-time Errors
Error detection methods
Using Services
Service usage
Custom Components
Writing components