Homework
Homework — see the compiler work
Homework — see the compiler work.
- Tooling. Install Node (if you don't have it). Create
package.jsonandtsconfig.json, runnpm install. You should get anode_modules/withtypescriptandvite. - Port one file. Copy the vanilla
detail.jstosrc/views/detail.tsand make a minimalsrc/types.tswith anApodtype (we expand it next lesson). Leavepic.hdurlandpic.copyright.trim()without guards. - Run the check.
npm run typecheck. Capture the two errors:TS2551(hdurl) andTS18048(copyright). These are real bugs in working code. - Prove "
.tswon't run in a browser". Try to includedetail.tsdirectly via<script>andpython -m http.server. It won't work. Runnpm run dev— Vite compiles it, it works. - 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 typecheckshowsTS2551andTS18048. - Tooling test:
.tsworks vianpm 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
Apodas a discriminated union onmedia_type, and "reach forhdurlon a video" simply won't compile. The bug becomes impossible to write.