Skip to content

fix(xdr): widen equals() param so union-typed values compile - #1637

Merged
Ryang-21 merged 1 commit into
mainfrom
fix/xdr-equals-union-types
Aug 13, 2026
Merged

fix(xdr): widen equals() param so union-typed values compile#1637
Ryang-21 merged 1 commit into
mainfrom
fix/xdr-equals-union-types

Conversation

@Ryang-21

Copy link
Copy Markdown
Contributor

Fixes #1630.

What

Widens the parameter of XdrValue.equals from polymorphic this to XdrValue, so the method is callable from TypeScript on union-typed values like xdr.ScVal, xdr.TransactionEnvelope, and xdr.Memo. The runtime body is unchanged: it already checks instanceof and constructor identity, so comparing two different XDR types compiles and returns false. Two kinds of tests guard the fix: a runtime suite (test/unit/xdr/equals.test.ts) pinning the structural-comparison contract, and a compile-time regression test (test/types/xdr-equals.ts) that exercises equals on every union named in the issue, on a struct, on a single arm against the union in both directions, and via a union-typed property read. A new test:types script (tsc -p test/types/tsconfig.json) runs it in CI next to the existing guide-snippet tsc gate, and the changelog gains a Fixed entry under Unreleased.

Why

With equals(other: this), polymorphic this in parameter position distributes over a union's arms and intersects them; discriminated classes with conflicting type literals reduce that intersection to never, so no argument can satisfy the call (TS2345) on any of the 88 union types the SDK returns, even though the runtime was correct. This is worse than a normal type wart because docs/XDR_MIGRATION.md prescribes equals() as the remedy for the v17 Buffer-to-Uint8Array assertion break, so the documented fix didn't compile on the types users actually hold. It shipped because nothing type-checked a call to equals: no test or internal caller touches it, and vitest strips types. The type test was verified to catch a regression by temporarily restoring the old signature, which reproduces the exact TS2345 from the issue.

Copilot AI balanced review requested due to automatic review settings August 12, 2026 17:56
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Widens XDR equality typing so union-typed values compile while preserving runtime behavior.

Changes:

  • Changes equals to accept any XdrValue.
  • Adds runtime and compile-time regression coverage.
  • Integrates type tests into CI and documents the fix.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/xdr/values/xdr-value.ts Widens the equality parameter type.
test/unit/xdr/equals.test.ts Tests runtime equality behavior.
test/types/xdr-equals.ts Covers union-type compilation.
test/types/tsconfig.json Configures compile-time tests.
package.json Adds the type-test command.
.github/workflows/tests.yml Runs type tests in CI.
CHANGELOG.md Records the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Ryang-21
Ryang-21 requested a review from quietbits August 12, 2026 20:18
@Ryang-21
Ryang-21 merged commit 599defa into main Aug 13, 2026
17 of 18 checks passed
@Ryang-21
Ryang-21 deleted the fix/xdr-equals-union-types branch August 13, 2026 19:17
@github-project-automation github-project-automation Bot moved this from Backlog (Not Ready) to Done in DevX Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

xdr equals() can't be called on any union type, which is what the SDK returns

3 participants