Skip to content

Improve compile-time machine diagnostics - #16

Merged
SandroMaglione merged 2 commits into
mainfrom
codex/improve-type-errors
Aug 2, 2026
Merged

Improve compile-time machine diagnostics#16
SandroMaglione merged 2 commits into
mainfrom
codex/improve-type-errors

Conversation

@SandroMaglione

Copy link
Copy Markdown
Member

Summary

  • localize invalid state-definition errors to the offending state node
  • attach event protocol errors to events or internalEvents instead of surfacing them through a validation rest parameter
  • preserve the handler-tree shape in validation errors and include the state path plus failing detail
  • validate incompatible machine-runtime requirements at the handler node
  • preserve contextual callback typing and the existing state, event, output, error, and service inference
  • add TST coverage for compatible and incompatible handler runtime requirements

Why

State, event, and handler validation previously collapsed failures into rest-parameter or root-level intersections. TypeScript consequently reported errors such as Expected 2 arguments or printed the complete machine or handler definition without identifying the configuration entry responsible for the failure.

The new validation overlays retain the authored object shape and use NoInfer so validation does not participate in configuration inference.

Type performance

Measured with TypeScript 6.0.3 and skipLibCheck=true.

Scenario Before After Difference
Machine.defineStates 2,894 2,894 0
Machine.make 8,334 7,817 -517 (-6.2%)
machine.handle 19,389 19,982 +593 (+3.1%)

Marginal instantiations, measured against the matching setup without the API call:

Scenario Before After Difference
Machine.defineStates +2,839 +2,839 0
Machine.make +5,432 +4,915 -517 (-9.5%)
machine.handle +11,055 +12,165 +1,110 (+10.0%)

The richer per-node handler diagnostics add 593 total instantiations in the representative handle scenario, while the refactored make validation removes 517 instantiations.

Validation

  • pnpm check
    • formatting and typecheck
    • build
    • 216 runtime tests
    • 102 TST tests / 419 assertions
    • strict consumer validation
    • package verification
  • pnpm perf:types

@SandroMaglione
SandroMaglione marked this pull request as ready for review August 2, 2026 12:24
@SandroMaglione
SandroMaglione merged commit 055d891 into main Aug 2, 2026
3 checks passed
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