Shared Types Package Strategy
Create a dedicated types package consumed across the monorepo.
Why a Shared Types Package?
Sharing types across frontend and backend eliminates drift between API contracts. A single source of truth means compile-time errors when the API shape changes.
// packages/types/src/index.ts
export interface User { id: string; name: string; email: string; }
export interface ApiResponse<T> { data: T; error?: string; }Package Structure
Keep the types package minimal: just type exports, no runtime logic. This keeps it side-effect-free and tree-shakable.
packages/types/
├── src/
│ ├── index.ts # re-exports all
│ ├── user.ts
│ ├── product.ts
│ └── api.ts
├── tsconfig.json
└── package.jsonAll lessons in this course
- TypeScript Project References Explained
- pnpm Workspaces with TypeScript
- Shared Types Package Strategy
- Incremental Builds and Cache in Monorepos