Skip to content

chore(types): add a typecheck script and @types/node - #164

Merged
cawalch merged 1 commit into
mainfrom
chore/typecheck-with-types-node
Nov 1, 2026
Merged

cawalch merged 1 commit into
mainfrom
chore/typecheck-with-types-node

Conversation

@cawalch

@cawalch cawalch commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Add a real typecheck gate. npx tsc --noEmit was the only way to typecheck, and it failed for two reasons: no @types/node, and two latent never-narrowing errors in TreeInterpreter.

• Add @types/node and a typecheck script (tsc --noEmit), and run it in CI after lint and in test:prod.
• Add "types": ["node"] to tsconfig.json. Without it, TypeScript 7 does not pick up the Node globals (process, console, ReadableStream, TextDecoder, node:fs, …) even with @types/node installed.
• Fix the two exhaustive-switch default branches in TreeInterpreter. TypeScript narrows the node to never once every Token case is handled, so reading node.operator for the error message is a type error. The branch is unreachable; the assertion keeps the diagnostic text and changes no behaviour.

These were real errors that the build never reported: tsdown only emits declarations for exported APIs, and cli.ts/Stream.ts are not typechecked unless tsc runs over the project.

Verification

On Node.js 26.13.0:

  • npm run typecheck — passes.
  • npm run lint:ci, npm run build, npm test — 1,380 tests passed; build artifacts test 21/21.
  • npm run coverage — unchanged: statements 95.66%, branches 91.93%, functions 95.83%, lines 95.54%.
  • npm audit — 0 vulnerabilities.

Note for a follow-up

The depth-limit test (enforces maxDepth option and defaults to DEFAULT_MAX_DEPTH) depends on visit()'s stack-frame size. Hoisting node.operator into a local made the 1,200-deep query overflow the JS stack before the 1,000 depth guard, which is why the fix keeps the access inline. That test would be more robust if it asserted the guard with a small explicit maxDepth instead of relying on native stack headroom.

Run the compiler directly and enforce the check in CI; it surfaced two latent errors.

• Add `@types/node` and a `typecheck` script (`tsc --noEmit`), run from CI and `test:prod`.
• Add `"types": ["node"]` to `tsconfig.json` so Node globals resolve under TypeScript 7.
• Fix the two `never`-narrowing errors in `TreeInterpreter`'s exhaustive operator switches; the runtime behaviour and diagnostic text are unchanged.
@cawalch
cawalch merged commit 539c85c into main Nov 1, 2026
9 checks passed
@cawalch
cawalch deleted the chore/typecheck-with-types-node branch November 1, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant