@repo/types package provides shared TypeScript type definitions that ensure type safety and consistency across all applications in the monorepo.
Installation
This package is internal to the monorepo and installed automatically:Features
- Type Safety: Shared types prevent inconsistencies across services
- Zero Runtime: Pure TypeScript types with no runtime overhead
- Centralized Definitions: Single source of truth for data structures
- IDE Support: Full IntelliSense and autocomplete support
Available Types
PriceUpdate
Represents a real-time price update from market data feeds.Usage Examples
Importing Types
WebSocket Price Updates
Redis Pub/Sub with Types
React Components
API Routes (Next.js)
Backend Services
Type Validation
Runtime Validation with Zod
While the types package doesn’t include runtime validation, you can combine it with Zod:Type Guards
Best Practices
Always import from @repo/types
Always import from @repo/types
Never duplicate type definitions across applications. Always import from the shared types package:
Use types for API contracts
Use types for API contracts
Define shared types for API request/response bodies to ensure consistency between frontend and backend:
Add JSDoc comments
Add JSDoc comments
Document types with JSDoc for better IDE support:
Keep types simple and focused
Keep types simple and focused
Each type should represent a single concept. Create separate types for different use cases:
Extending Types
Creating Derived Types
Union Types
Testing with Types
Related Packages
@repo/config
Uses types for configuration validation
@repo/db
Prisma generates database types
@repo/utils
May use shared types for utility functions