Skip to content

Replace any types with specific types across SDK and demo packages#339

Open
daatsuka wants to merge 2 commits into
ethereum-optimism:mainfrom
daatsuka:replace-any-types-with-specific
Open

Replace any types with specific types across SDK and demo packages#339
daatsuka wants to merge 2 commits into
ethereum-optimism:mainfrom
daatsuka:replace-any-types-with-specific

Conversation

@daatsuka
Copy link
Copy Markdown

This change sweeps through 23 files in packages/sdk, packages/demo/backend, and packages/demo/frontend to eliminate every @typescript-eslint/no-explicit-any suppression. In the SDK source layer, the biggest wins are in lend/providers/morpho/api.ts and lend/providers/morpho/sdk.ts: fetchRewards now returns a properly typed MorphoVaultApiResponse instead of any, backed by four new interfaces (MorphoRewardAsset, MorphoReward, MorphoMarketAllocation, MorphoVaultState) that model the Morpho GraphQL schema. calculateBaseApy, calculateApyBreakdown, and calculateRewardsBreakdown in sdk.ts receive a structural MorphoSdkVault interface instead of any, and the inline AccrualPosition cast is gone — the reducer callback and allocation.position are now typed through MorphoSdkAllocation/MorphoSdkPosition. In aave/sdk.ts, calculateApyBreakdown's formattedReserve parameter moves from any to { supplyAPY?: string }. Over in utils/test.ts, the Anvil RPC calls (anvil_impersonateAccount / anvil_stopImpersonatingAccount) are handled via a structural cast on publicClient.request instead of casting the method string to any, and the redundant as any on createWalletClient is simply removed because viem's types already match.

In test files the pattern is consistent: every as any mock cast becomes as unknown as <ConcreteType>, where <ConcreteType> is derived from the function's actual return type — e.g. ReturnType<typeof getActions>, Awaited<ReturnType<typeof fetchAccrualVault>>, Context (from Hono), PublicClient, BundlerClient, Asset, SupportedChainId, or Awaited<ReturnType<typeof toCoinbaseSmartAccount>>. This two-step cast through unknown is the standard TypeScript escape hatch when building partial mocks: it satisfies the compiler while still documenting the intended type at the call site. The Morpho API test (api.test.ts) adds narrowing guards (if (!vaultData) throw new Error('unreachable')) before property access so the non-null assertions are explicit rather than silently swallowed by any. The DynamicWallet.spec.ts error-cause access switches from (err as any).cause to (err as Error & { cause?: Error }).cause, preserving type safety on the chained cause.

The design intent is to make every any removal a local, minimal change — introduce the narrowest structural interface that satisfies the call site, prefer ReturnType/Awaited utility types over hand-rolled duplicates, and avoid pulling in heavy external type packages. The Solidity file DeployMorphoMarket.s.sol only has a formatting adjustment that crept in from the linter pass. I ran pnpm typecheck and pnpm lint across the entire monorepo after the changes, confirming zero type errors and that the no-explicit-any warning count drops to zero in all touched files.

Closes #337

@daatsuka daatsuka requested a review from a team as a code owner March 27, 2026 00:13
@daatsuka daatsuka requested a review from its-everdred March 27, 2026 00:13
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 27, 2026

👷 Deploy request for actions-ui pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 2d4c905

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.

Replace all any types with specific types

1 participant