village-builder

VB-380: A formatter, and the files become TypeScript

Status: blocked Waits for: VB-378, VB-379 Priority: 3 Size: M Arch: yardstick Phase: implement Design ref: none (code structure). docs/typescript-plan.md (P8); the survey in backlog/VB-055.md. Goal: One sweep, so that every file is rewritten once: (1) rename the 63 modules *.js to *.ts with git mv in a commit of its own (rename only, so history follows); (2) src/ (the modules and src/page/*.js, which stay .js: the page is a script spliced into one closure, 623 top-level names on 12 November) is formatted and Prettier installed at an exact version, print width 120, single quotes (13 Nov, tests/format.js); what is left is the rename to .ts, tests/ and tools/ formatted in a commit of their own, listed in .git-blame-ignore-revs, and tools/wrap.js gone. This also re-indents the module bodies that VB-376 to VB-378 left as they were. Imports name the extension (from './x.ts'; Node’s type stripping needs it, tried in a scratch directory on 12 November), only erasable syntax is allowed (no enum, namespace or parameter properties; Node refused all three there), nothing but the page’s bundle is built: Node runs the .ts modules as they are. tools/wrap.js, its test, the lint’s 160 columns and its 400 lines go in this task (the formatted sim/relations is 691 lines, sim/heirs 651, so the cap cannot stay); tsconfig.json is added with noEmit, allowImportingTsExtensions, erasableSyntaxOnly (TypeScript 5.8 or later: to verify), not strict, and the files are // no checking yet in effect, since nothing is annotated (tsc --noEmit joins npm test in VB-382). Measured on 12 November (Prettier 3.3.3, width 120, single quotes, the defaults otherwise, over a copy of src/sim, src/gen, src/gen.js, src/culture.js, src/sim.js, src/vb.js): 11,917 lines become 19,722; sim/relations 691, sim/heirs 651, sim/records 725, gen.js 1,044. Functions over 60 lines go from 11 to 26 (largest: gen.js:generate 257 to 486). Acceptance criteria: