Monorepos & Project References
Create a workspace monorepo and wire TypeScript Project References for fast, incremental builds and clean inter-package types.
Monorepos & Project References is a free TypeScript Academy lesson on CoddyKit — lesson 1 of 1. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 1 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Intro
Goal: Organize a monorepo that scales. You will declare workspaces, add Project References, and build with tsc -b for incremental output.
- pnpm/yarn workspaces
- Composite projects
- Shared types
Workspace layout
A simple two-package layout: shared (library) and app (depends on shared). Workspaces link local packages.
# folder structure (for reference)
/monorepo
package.json
tsconfig.base.json
packages/
shared/
src/index.ts
package.json
tsconfig.json
app/
src/index.ts
package.json
tsconfig.jsonRoot workspaces
Declare workspaces so the package manager links local deps. Add build/clean scripts using the TS build mode.
// package.json (root)
{
"name": "monorepo",
"private": true,
"workspaces": ["packages/*"],
"scripts": {
"build": "tsc -b packages/*",
"clean": "tsc -b packages/* --clean"
}
}Shared package
Mark the library as a composite project. Emit declarations so dependents can type-check quickly.
// packages/shared/tsconfig.json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"composite": true
},
"include": ["src"]
}
// packages/shared/src/index.ts
export interface User { id: string; name: string }
export const hello = (u: User) => `Hello, ${u.name}`App package + refs
Add a references entry to depend on shared. The builder compiles shared first, then app.
// packages/app/tsconfig.json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"composite": true
},
"references": [
{ "path": "../shared" }
],
"include": ["src"]
}
// packages/app/src/index.ts
import { hello } from "shared"
console.log(hello({ id: "u1", name: "Ada" }))Base config & tips
Tips:
- Create
tsconfig.base.jsonfor shared compiler options. - Use
pathsmappings that mirror package names. - Run
tsc -b --watchfor incremental local dev.
References requirement check
Quick check: What must each referenced package include?
Recap
Recap: Workspaces link local packages; Project References (composite + references) unlock fast, incremental tsc -b builds and reliable cross-package types.
Frequently asked questions
Is the “Monorepos & Project References” lesson free?
Yes — the full text of “Monorepos & Project References” is free to read here on the web, and the TypeScript Academy course includes 1 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Monorepos & Project References”?
Create a workspace monorepo and wire TypeScript Project References for fast, incremental builds and clean inter-package types. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 1, so you can start here or from the beginning and move at your own pace.
How long does the “Monorepos & Project References” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.