Homework

Homework — see the compiler work

Homework — see the compiler work.

  1. Tooling. Install Node (if you don't have it). Create package.json and tsconfig.json, run npm install. You should get a node_modules/ with typescript and vite.
  2. Port one file. Copy the vanilla detail.js to src/views/detail.ts and make a minimal src/types.ts with an Apod type (we expand it next lesson). Leave pic.hdurl and pic.copyright.trim() without guards.
  3. Run the check. npm run typecheck. Capture the two errors: TS2551 (hdurl) and TS18048 (copyright). These are real bugs in working code.
  4. Prove ".ts won't run in a browser". Try to include detail.ts directly via <script> and python -m http.server. It won't work. Run npm run dev — Vite compiles it, it works.
  5. Reflect. How many more such optional/union bugs hide across the vanilla code? (You'll see the answer when you port the whole app.)

Required tests:

  • Errors test: npm run typecheck shows TS2551 and TS18048.
  • Tooling test: .ts works via npm run dev, not via a static server.

To submit: screenshots: (1) npm run typecheck with the two errors, (2) the app running through the Vite dev server.

Next. We saw the problem and got the tool. In lesson 16 we fix those errors: we describe Apod as a discriminated union on media_type, and "reach for hdurl on a video" simply won't compile. The bug becomes impossible to write.