Status: blocked
Waits for: VB-380
Priority: 3
Size: M
Arch: yardstick
Phase: implement
Design ref: none (code structure). docs/typescript-plan.md (P10); the survey in backlog/VB-055.md.
Goal: src/types.ts holds the shapes of the state: State, World (w), Pawn, Household, Farmstead, Village, Job, Agent, Plot, Store and the like, written from the 117 @state lines (24 files; 33 in sim/scenarios, 21 in gen.js) and from the plain-data invariants in tests/lib/invariants.js. st is plain data as a type: Plain<T> (no function, no class instance, no Map or Set where tests/plaindata.js forbids them; typed arrays where the world has them). The @state lines go, or each becomes one line pointing to its type (// @state: see State.tick), and tests/lint.js’s rule “every top-level key of w and st has an @state tag” is replaced by a type check: a list of keys as const satisfies readonly (keyof State)[] and a type that fails when a key is missing (to verify that this is expressible), compared in a test with the keys of a seeded state. tsc --noEmit runs in npm test. Modules are annotated only at the signatures of exported functions that take st, hh, pawn, farm, village and job (st: State), not yet inside.
Acceptance criteria:
src/types.ts, tsconfig.json (not strict yet) and a script tests/types.js that runs tsc --noEmit -p . (TypeScript at an exact version; the time it takes in npm test before and after is in the task file; on 12 November it took 5.4 s over the 62 modules with checkJs, on a loaded machine, against 2 s on 10 November).// @ts-expect-error <why> (counted in the task file) where the type is too narrow; the number of expect-errors is a baseline that only falls.hh.grian) fails npm test: a test file tests/types-negative.ts holds a few lines that must not compile and tsc is run on it expecting errors.tests/plaindata.js and tests/saves.js still hold; a Plain<State> assertion shows no function field.AGENTS.md (Finding things: “state schema: grep -rn "@state" src” becomes src/types.ts; Conventions on st and the WORLD list) and docs/architecture/modules.md, target-v2.md (section 4’s note): a line each.docs/typescript-plan.md, where this task is P10): waits for Kim’s answers to QUESTIONS.md, “VB-055: the move to TypeScript” (the formatter, the bundler, the hook, the width measures, when, the page and the tests, strict), which may change its criteria; the three rules common to these tasks are at the top of the plan.docs/review-blocks.md): Job and Agent change shape with VB-472 and VB-473 (a task’s reckoning fields; a pawn’s leg); write the types after them, or expect to rewrite those two.