Module 29: Modules, Classes, Generics and Utility Types

Lesson 5 of 5 · 15–25 minutes

Organising a project

🏠The everyday picture

A well-run office: departments by subject, a reception that directs visitors, and a manual on the front desk explaining where everything is.

📘What it really is

inventory/
  src/
    types.ts       shared types
    data.ts        sample or stored data
    inventory.ts   stock logic
    expenses.ts    expense logic
    utils.ts       small general helpers
    app.ts         starts the program
  tests/
    inventory.test.ts
  package.json
  tsconfig.json
  README.md
  .gitignore

🖱️Try it

Reorganise your inventory project into the structure above. Add "start": "node src/app.ts" to the scripts, and move or write at least three tests into tests/. Check that npm start, npm test and npm run check all work.

✅Quick check

Why should calculation files never print or save?

Show the answer

Keeping logic pure makes it easy to test and reuse; input and output stay in one place.

inventory.ts imports from app.ts, and app.ts imports from inventory.ts. What's wrong?

Show the answer

A circular dependency. Dependencies should point one way, with app.ts at the top.

← PreviousUtility types
ProLearners Assist