Skip to content

Make getPriority optional with a default of 0 - #7

Merged
thomasrepnik merged 2 commits into
masterfrom
optional-get-priority
Nov 9, 2026
Merged

thomasrepnik merged 2 commits into
masterfrom
optional-get-priority

Conversation

@thomasrepnik

Copy link
Copy Markdown
Owner

Most Dispatchable implementations don't overlap: isApplicableTo already picks exactly one, so getPriority() { return 0; } was boilerplate.

Dispatchable is a type-only interface and can't carry a default body. Instead, getPriority is now optional, and resolveDelegate and the generated dispatcher treat a missing one as 0. Ties still throw, so two applicable implementations without a priority still raise the Ambiguous error. Existing implementations work as before.

Changes

  • src/index.ts: getPriority?(): number
  • src/dispatcher.ts: when choosing an implementation and in error messages, a missing priority counts as 0. The generated forwarder returns getPriority?.() ?? 0.
  • Tests:
    • new resolveDelegate and dispatcher cases for implementations without a priority
    • a check-layout test that accepts implementations with and without getPriority
  • Example and README: PlainTextFormatter drops its priority, and the README documents the default.
  • Refactor skill: leaves getPriority out wherever it would return 0.
  • Evals:
    • the reference solutions drop getPriority wherever it returned 0
    • conventions.mjs reports a missing priority as -

Verification

  • npm run typecheck && npm test: 71 tests pass
  • evals/refactor-skill/scripts/validate.mjs: all 8 scenarios OK
  • conventions.mjs on the reference runs: 7/7 priorities match

Most dispatchable implementations don't overlap: isApplicableTo already
picks exactly one, so getPriority() { return 0; } was boilerplate.
Dispatchable is a type-only interface and can't carry a default body, so
the method is now optional and resolveDelegate and the generated
dispatcher treat a missing one as 0. Ties still throw, so two applicable
implementations without a priority remain an Ambiguous error.

The refactor skill now leaves getPriority out wherever it would return
0. The eval references drop it accordingly, and conventions.mjs reports
a missing priority as '-' and expects it for exclusive scenarios.
Says that the skill is opinionated about layout and naming, and that it
can serve as a blueprint for refactoring existing code onto ts-implscan.
@thomasrepnik
thomasrepnik merged commit 39ec84f into master Nov 9, 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