Skip to content

fix: improve type safety for MessageContext payload handling#10

Merged
koistya merged 1 commit into
mainfrom
dev
Oct 1, 2025
Merged

fix: improve type safety for MessageContext payload handling#10
koistya merged 1 commit into
mainfrom
dev

Conversation

@koistya

@koistya koistya commented Oct 1, 2025

Copy link
Copy Markdown
Member

Summary

Fixes type inference issue where ctx.payload was incorrectly available for message schemas without payload definitions. The fix uses explicit keyof checks instead of structural extends to properly handle discriminated unions and prevent false type matches.

Changes:

  • Updated MessageContext type in both Zod and Valibot adapters to use keyof check for payload existence
  • Added type property to MessageContext for accessing message type literal
  • Enhanced TSDoc comments across shared types for better documentation
  • Added comprehensive type-level tests for both adapters
  • Created specs and ADRs documenting the fix and architecture decisions
  • Version bump to 0.4.4

Why this matters:
TypeScript's structural typing can match optional properties against extends checks, causing the previous implementation to incorrectly add payload to contexts for payload-less schemas. The keyof approach explicitly checks for key existence, ensuring proper type safety.

@koistya
koistya merged commit d7ed677 into main Oct 1, 2025
3 checks passed
@koistya
koistya deleted the dev branch October 1, 2025 13:53
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