Repository navigation
fix(io-ts-http): allow non-JSON decoded body types in GenericHttpRequest - #1210
Open
sharmis-tp wants to merge 1 commit into
Open
sharmis-tp wants to merge 1 commit into
sharmis-tp wants to merge 1 commit into
Conversation
sharmis-tp
force-pushed
the
fix/generic-request-bigint-body
branch
from
October 14, 2026 04:15
1b70627 to
52b2388
Compare
This branch has not been deployed
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.
Closes #1116.
GenericHttpRequesttyped its body asoptional(Json), which constrains both the decoded and the encoded type toJson. A route that intersects it with a body codec decoding to non-JSON values, such asBigIntFromString, could not be called throughsuperagent-wrapper:RequestType<Route>made the body(Json | undefined) & { amount: bigint }, so.post({ params: {}, query: {}, body: { amount } })failed with TS2322.route.request.encodethrewno codec found to encode value in union type (Json | undefined). The union picks its member withJson.is, which rejects the bigint, so the request never reached the wire.Change
As discussed in the issue, the body is now
optional(JsonBody), whereJsonBodyis at.Type<unknown, Json, unknown>:unknown, which matches the documentedbody?: unknown.isaccepts any value, so the route's own body codec does the encoding.Json, soHttpRequestCodecstill requires a route's body codec to encode to JSON.Json, and the codec keeps the nameJson, so server-side decoding and its error messages are unchanged.Tests
io-ts-http:GenericHttpRequestintersected with aBigIntFromStringbody decodes'100'to a bigint and encodes it back to'100'. The test assigns a bigint body tot.TypeOf<typeof Request>, so the build fails without this change.superagent-wrapper: a route with a bigint body is posted through the client. The server receives the amount as a string, and the response decodes back to a bigint.Without the change, the build fails with TS2322 and both runtime tests fail with the union encode error. With it,
npm run buildpasses andnpm testpasses in every package.