Replace explicit any with proper types in onchain/soroban (1/3)#147
Replace explicit any with proper types in onchain/soroban (1/3)#147noevidence1017 wants to merge 1 commit into
Conversation
kilodesodiq-arch
left a comment
There was a problem hiding this comment.
Thanks @noevidence1017 — the type cleanup is in the right direction, but Id like this split before merging:
- The 41-file blast radius is too big for one PR. Please split into 2–3 PRs grouped by area (e.g. onchain adapters & soroban mappings, request/express middleware, error filters).
- Please hold off on flipping
@typescript-eslint/no-explicit-anyfromwarntoerrorinside this PR. That change will instantly fail CI for every other open PR (and any fork). Bring the lint rule flip in as its own one-line PR once the type refactors have landed on main. - Sanity-check the new interfaces for
as SomeTypecasts that may be masking real shape mismatches at the Soroban / Prisma boundaries.
Re-review once split.
Scopes the type-safety work to the onchain adapters, processor, services and Soroban error mapping (split out from the original 41-file PR per review). Does NOT flip the @typescript-eslint/no-explicit-any rule — that will land as its own one-line PR once the type refactors are merged. - Introduce a discriminated union for OnchainJobData/OnchainJobInput so the processor narrows params/result per operation type. - Replace duck-typed any error handling in soroban-error.mapper.ts with unknown plus a minimal SorobanErrorLike interface. - Validate the AidPackage status decoded from RPC against the known union (parsePackageStatus) instead of an unchecked `as` cast at the Soroban boundary. - Add a shared contract-value helper (toContractString/toStringRecord) to coerce unknown RPC values without [object Object] stringification, and fix the AidPackage.metadata Record<string,string> mismatch. - Skip ledger-backfill entries with no resolvable campaignId (required on BalanceLedger) rather than failing the whole range. - Make AidEscrowController handlers and the onchain processor exhaustive so concrete return types type-check. Verified: tsc --noEmit clean, eslint clean (0 errors), onchain Jest suites pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
668acb1 to
16cd758
Compare
|
Thanks for the review @kilodesodiq-arch — addressed all three points:
One heads-up while doing this: the original branch didn't actually compile or lint ( |
|
Thanks @noevidence1017 for starting the type-safety work. Backend CI is green for this slice, but since this PR only covers the onchain/soroban portion (1/3), issue #99 won't fully resolve until the rest of the codebase is addressed. Could you follow up with the remaining 2/3 in separate PRs (or update this one's scope to indicate the subset) before we merge? Holding the merge in the meantime so the issue stays open for the follow-ups. |
Summary
Re-scoped per review (#147 was 41 files). This PR is now just the onchain / Soroban group; the other two groups are staged as separate branches and will follow as their own PRs once this lands:
fix/type-safety-express-middleware— request/express middleware, interceptors, guards,express.d.tsfix/type-safety-prisma-filters— global exception filter, Prisma-backed services, frontendThe
@typescript-eslint/no-explicit-anywarn→errorflip has been removed from this PR and will come last as its own one-line change, once the refactors are onmain(so it doesn't break other open PRs/forks).What's in this PR (onchain only)
OnchainJobData/OnchainJobInputsoonchain.processor.tsnarrowsparams/resultper operation type.unknown+ a minimalSorobanErrorLikeinterface insoroban-error.mapper.tsinstead of duck-typedany.onchain.adapter.ts,soroban.adapter.ts,soroban-onchain.adapter.ts,ledger-backfill/reconciliation.service.ts,aid-escrow.controller.ts.Addressing review feedback
pkg?.status as AidPackage['status']insoroban-onchain.adapter.tsis replaced with aparsePackageStatus()guard (mirroringsoroban.adapter.ts), and theAidPackage.metadata/String(unknown)boundary conversions now go through a smallcontract-valuehelper (toContractString/toStringRecord) instead of[object Object]-prone casts.Verification
tsc --noEmitcleaneslintclean (0 errors) on the onchain filesCloses #99