Step 1: The strictest type checker
Step 1: The strictest type checker
The first step of the harness I put around my coding agents: the type checker at its strictest, before the agent writes a line, flag by flag.
Part of the series: Codebase Harness, Step by Step · View all parts
The code compiled and didn't work. I couldn't fix it myself; I asked the agent, and another error surfaced. What stopped them: the type checker at its strictest, before the agent writes a line. In TypeScript: strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes.
Two dimensions. A guide acts before the agent, a sensor after. Each is inferential, judged by a model, or computational, decided by a program. Inferential guides are what the agent reads, AGENTS.md, a skill, a plan, sharper written in the literature's words; computational guides are deterministic tools, a codemod, a generator, a command that acts in the agent's place, code mode, where the agent writes a program instead of a string of actions, a language server. Inferential sensors are a review by a model or a person; computational sensors are the type checker, the linter, tests and fitness functions. Each practice moves a judgement toward computation, and the computational sensor is the optimum.
- 1 · type checkertoday
In Birgitta Böckeler's grid of guides and sensors, the type checker is a computational sensor: a program answers true or false, the same every time. It holds without your attention. The series' map: Guides and Sensors: Mapping Your Attention to Free It
The details, flag by flag
strict is the floor: no implicit any, null and undefined checked, catch variables typed unknown. Every flag after it closes a gap strict leaves open.
noUncheckedIndexedAccess: arr[i] and record[key] are T | undefined. The agent has to handle the missing case instead of assuming it is there. It turns a whole family of runtime errors into compile errors the agent must fix.
exactOptionalPropertyTypes: an optional property may be absent, not set to undefined. noPropertyAccessFromIndexSignature: a key that may not exist is read with brackets, so it shows in the code.
Then the flags for what an agent leaves behind: noUnusedLocals, noUnusedParameters, noImplicitReturns, noFallthroughCasesInSwitch, noImplicitOverride, allowUnreachableCode false.
If you want an example, here is the tsconfig of one of my tools: lbdremy/phax/tsconfig.json
Next in this series: Step 2: The strictest linter
A thought after reading?
If you would like to discuss about this article, you can write to me here. I share because I care and I want to learn. Please teach me with care.