Skip to content

fix(io-ts-http): allow non-JSON decoded body types in GenericHttpRequest - #1210

Open
sharmis-tp wants to merge 1 commit into
BitGo:masterfrom
sharmis-tp:fix/generic-request-bigint-body
Open

sharmis-tp wants to merge 1 commit into
BitGo:masterfrom
sharmis-tp:fix/generic-request-bigint-body

Conversation

@sharmis-tp

Copy link
Copy Markdown

Closes #1116.

GenericHttpRequest typed its body as optional(Json), which constrains both the decoded and the encoded type to Json. A route that intersects it with a body codec decoding to non-JSON values, such as BigIntFromString, could not be called through superagent-wrapper:

  • Types: RequestType<Route> made the body (Json | undefined) & { amount: bigint }, so .post({ params: {}, query: {}, body: { amount } }) failed with TS2322.
  • Runtime: with the type error bypassed, route.request.encode threw no codec found to encode value in union type (Json | undefined). The union picks its member with Json.is, which rejects the bigint, so the request never reached the wire.

Change

As discussed in the issue, the body is now optional(JsonBody), where JsonBody is a t.Type<unknown, Json, unknown>:

  • The decoded type is unknown, which matches the documented body?: unknown. is accepts any value, so the route's own body codec does the encoding.
  • The output type stays Json, so HttpRequestCodec still requires a route's body codec to encode to JSON.
  • Decoding still validates with Json, and the codec keeps the name Json, so server-side decoding and its error messages are unchanged.

Tests

  • io-ts-http:
    • GenericHttpRequest intersected with a BigIntFromString body decodes '100' to a bigint and encodes it back to '100'. The test assigns a bigint body to t.TypeOf<typeof Request>, so the build fails without this change.
    • A second test checks that decoding still rejects a non-JSON body.
  • 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 build passes and npm test passes in every package.

@sharmis-tp
sharmis-tp requested a review from a team as a code owner October 14, 2026 03:09
@sharmis-tp
sharmis-tp force-pushed the fix/generic-request-bigint-body branch from 1b70627 to 52b2388 Compare October 14, 2026 04:15

This branch has not been deployed

No deployments
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.

GenericHttpRequest body constraint rejects codecs that decode to bigint

1 participant