fix(sdk): replace any with typed generics in unified scanner adapter API - #227
Open
Jerryvic911 wants to merge 2 commits into
Open
Jerryvic911 wants to merge 2 commits into
Jerryvic911 wants to merge 2 commits into
Conversation
Replace any defaults on ChainScannerAdapter and CustomChainInput with
unknown, so the public adapter API carries real generic constraints
instead of an escape hatch that defeated type checking entirely.
encodeMetaAddress params are explicitly unknown since key material
differs per chain. ScanAllInput.adapters now accepts a heterogeneous
array of CustomChainInput without any, relying on bivariant method
checking for soundness. The custom-adapter arm of MatchedAnnouncement
now carries unknown instead of any, completing the discriminated
union. Drops two undocumented, untyped fallback shapes in the
scanAll() custom-adapter loop (bare adapter object, { input: {...} })
that were never used in tests, docs, or examples and made real
generic constraints impossible.
Adds test/scanner/unified.test-d.ts, a new compile-time usage test
file run via vitest's --typecheck.only mode (wired up as pnpm run
test:types), verifying adapter generics narrow correctly, mismatched
CustomChainInput generics are rejected at compile time, and the
discriminated union holds.
Closes wraith-protocol#201
|
@Jerryvic911 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
The custom arm is not discriminated yet. chain: string overlaps the built-in chain names, so announcement stays unknown even after checking for evm. Please fix that narrowing and run test:types in CI. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace any defaults on ChainScannerAdapter and CustomChainInput with unknown, so the public adapter API carries real generic constraints instead of an escape hatch that defeated type checking entirely. encodeMetaAddress params are explicitly unknown since key material differs per chain. ScanAllInput.adapters now accepts a heterogeneous array of CustomChainInput without any, relying on bivariant method checking for soundness. The custom-adapter arm of MatchedAnnouncement now carries unknown instead of any, completing the discriminated union. Drops two undocumented, untyped fallback shapes in the scanAll() custom-adapter loop (bare adapter object, { input: {...} }) that were never used in tests, docs, or examples and made real generic constraints impossible.
Adds test/scanner/unified.test-d.ts, a new compile-time usage test file run via vitest's --typecheck.only mode (wired up as pnpm run test:types), verifying adapter generics narrow correctly, mismatched CustomChainInput generics are rejected at compile time, and the discriminated union holds.
Closes #201