# TypeScript Basics Study Plan

This exercise takes a working JavaScript book catalog and adds TypeScript one
idea at a time. Read `src/index.ts` beside this guide.

## Study order

1. **Interface:** `Book` describes the required fields and their types. Its
   `status` must be a `BookStatus`, so an unrelated string cannot be stored.
2. **Typed array:** `Book[]` means the catalog may contain only books.
3. **Enum:** `BookStatus` gives names to the three allowed status strings and
   prevents spelling variations throughout the program.
4. **Function signatures:** parameter and return types document each function
   and let TypeScript check every call.
5. **Union type:** `BookFilter = string | number` allows an author or a year.
   The `typeof` check narrows the union before comparison.
6. **Generic:** `getFirstItem<Item>` preserves the item type for any array. A
   book array produces `Book | undefined`; a string array would produce
   `string | undefined`.

`findBookByTitle()` and `getFirstItem()` may return `undefined` when no item
exists. The demo uses optional chaining (`?.`) so that possibility is handled
instead of ignored.

## Exercises and checkpoints

- Run `npm run typecheck`. Explain why it prints no output when successful.
- Run `npm run build && npm start` and compare every output line with the
  README.
- Add a practice book with an invalid status string and read the compiler
  error. Remove it afterward.
- Call `findBooksBy()` with a boolean and read the compiler error. Remove the
  call afterward.
- Call `getFirstItem()` with `[1, 2, 3]` and hover over the result in your
  editor. TypeScript should infer `number | undefined` without `any`.

The central idea is that TypeScript checks assumptions before the program
runs. It does not replace the JavaScript program; the build step produces
JavaScript that Node executes.
