fix(api-sync): widen untyped body literals before conditional field assignment - #25
Merged
Merged
Conversation
…ssignment
The generator's applyResourcesField always inserts
"if (options.x !== undefined) body.field = options.x" after a function's
existing body declaration. That only typechecks when body is already
Record<string, any> (createBankAccount, updateCustomer, ...); functions
that still declare a plain "const body = {...}" literal (createQuote,
createPayin, ...) get a closed object type, so the new assignment fails
with TS2339. This is what broke the API Sync run that tried to add
refund_wallet_address to createQuote's body: the field itself is live on
the current QuoteIn schema and used by the payouts refund path, only the
generator's patch was wrong.
Widen the declaration to Record<string, any> whenever the generator adds
a conditional field to an untyped body literal, matching the convention
already used by hand-written conditional-field functions.
Claude-Session: https://claude.ai/code/session_01F1stiNzuNtJXoXtiW9ZCbs
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.
Summary
The API Sync workflow failed with:
This is a bug in the deterministic generator (
scripts/api-sync/apply.ts), not a spec problem:refund_wallet_addressis a live, currently-supported field onQuoteIn(confirmed againstorigin/api-sync-data:.api-sync/spec-current.json, and it is read and used by the refund-on-failure job in the API).applyResourcesFieldalways insertsif (options.x !== undefined) body.field = options.xafter the existing body declaration. That only typechecks whenbodyis already declaredRecord<string, any>(e.g.createBankAccount,updateCustomer). Functions that still declare a plainconst body = {...}literal (likecreateQuote) get a closed object type from TS, so the new assignment fails to compile.Fix
applyResourcesFieldnow widens an untypedconst body = {toconst body: Record<string, any> = {whenever it adds a conditional field assignment, matching the convention already used by every hand-written function that assigns fields conditionally.Verification
Reran the real changelog from
origin/api-sync-datathrough the generator locally with the fix applied: it produces the samequotes.create: +refund_wallet_addresschange as before, but the result now passesbun run typecheck,bun run lint,bun test, andbun run build. Reverted that generated diff before committing since it's the API Sync workflow's job to produce and merge it, not this PR's.Test plan
bun run typecheckbun run lintbun test(125 pass, including two new regression tests: widening an untyped body, and leaving an already-typed body untouched)bun run buildhttps://claude.ai/code/session_01F1stiNzuNtJXoXtiW9ZCbs