Skip to content

TypeScript error: BinaryResponse.d.ts references Response.bytes which doesn't exist in @types/node 18-22 #233

@LA

Description

@LA

Summary

After upgrading from square@43.1.0 to square@44.0.0, our CI build fails with a TypeScript compilation error in BinaryResponse.d.ts.

Error

node_modules/square/core/fetcher/BinaryResponse.d.ts:17:35 - error TS2339: Property 'bytes' does not exist on type 'Response'.

17     bytes?(): ReturnType<Response["bytes"]>;
                                     ~~~~~~~

Minimal Reproduction

https://github.com/hookedapp/square-sdk-44-response-bytes-type-error

git clone https://github.com/hookedapp/square-sdk-44-response-bytes-type-error.git
cd square-sdk-44-response-bytes-type-error
pnpm install
pnpm gen:meta   # fails

Root Cause

BinaryResponse.d.ts declares:

bytes?(): ReturnType<Response["bytes"]>;

Although the property is optional, TypeScript still resolves ReturnType<Response["bytes"]>, which requires bytes to exist on the global Response interface.

In Node.js, Response is typed by undici-types. Response.bytes() is only defined in undici-types@7.x, but no current @types/node version (18, 20, or 22) depends on undici-types@7.x:

@types/node undici-types Has Response.bytes()
18.x ~5.26 No
20.x ~5.26 No
22.x ~6.21 No
25.x ~7.18 Yes

The SDK specifies engines.node >= 18 and develops against @types/node@^18.19.70, so any consumer on Node 18–22 with skipLibCheck: false will hit this.

Suggested Fix

Replace the derived return type with a concrete one:

- bytes?(): ReturnType<Response["bytes"]>;
+ bytes?(): Promise<Uint8Array>;

This preserves the same runtime behavior without depending on the consumer's Response type definition.

Environment

  • square: 44.0.0
  • typescript: 5.5.x
  • @types/node: 20.x (also tested with 18.x and 22.x)
  • skipLibCheck: false
  • Node.js: 20.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions