Fix ~80s consumer type-checks of client aliases (#500)#525
Merged
Conversation
Checking a client created by createSmartAccountClient, createPimlicoClient, or createPasskeyServerClient against its bare alias (e.g. useQuery<SmartAccountClient>) forced TypeScript to structurally expand the full action surface on every call site: ~82s / 481k type instantiations in the issue's reproduction. The client aliases now use an inline mapped-type body over a private *Inner alias, with variance annotations on the type parameters (the same pattern viem ships in SimulateContractReturnType, wevm/viem#2557). Both sides of a comparison then carry the alias's identity, so tsc compares instantiations argument-by-argument instead of expanding them: the issue's repro drops to 0.44s / 149k instantiations. rpcSchema is deliberately left unannotated so a pairwise mismatch falls back to the structural check rather than rejecting assignments that compile today. Return-type precision is unchanged. The mapped types must stay inline: extracting them into a shared helper (e.g. Flatten<T>) re-attaches the helper's alias identity instead and restores the slowdown (measured: 444k instantiations, no improvement). The type-consumer fixture now guards all of this against the packed tarball: Equal-assertions that account/chain/client stay exactly inferred (what PR #511 would have widened), bare-alias assignability (which fails loudly if the variance fast path ever hard-rejects), and custom-rpcSchema fallback for all three clients. Closes #500. Supersedes #511. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: f1fb04b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #525 +/- ##
=======================================
Coverage 78.41% 78.41%
=======================================
Files 105 105
Lines 8988 8988
Branches 570 570
=======================================
Hits 7048 7048
Misses 1914 1914
Partials 26 26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mouseless0x
approved these changes
Jul 9, 2026
Contributor
size-limit report 📦
|
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.
Checking a client created by createSmartAccountClient, createPimlicoClient, or createPasskeyServerClient against its bare alias (e.g. useQuery) forced TypeScript to structurally expand the full action surface on every call site: ~82s / 481k type instantiations in the issue's reproduction.
The client aliases now use an inline mapped-type body over a private *Inner alias, with variance annotations on the type parameters (the same pattern viem ships in SimulateContractReturnType, wevm/viem#2557). Both sides of a comparison then carry the alias's identity, so tsc compares instantiations argument-by-argument instead of expanding them: the issue's repro drops to 0.44s / 149k instantiations. rpcSchema is deliberately left unannotated so a pairwise mismatch falls back to the structural check rather than rejecting assignments that compile today. Return-type precision is unchanged.
The mapped types must stay inline: extracting them into a shared helper (e.g. Flatten) re-attaches the helper's alias identity instead and restores the slowdown (measured: 444k instantiations, no improvement).
The type-consumer fixture now guards all of this against the packed tarball: Equal-assertions that account/chain/client stay exactly inferred (what PR #511 would have widened), bare-alias assignability (which fails loudly if the variance fast path ever hard-rejects), and custom-rpcSchema fallback for all three clients.
Closes #500.