Skip to content

Uint8Array<ArrayBufferLike> byte fields are rejected wherever BufferSource is required #1688

Description

@oceans404

Impact: low. Compile-time error, so it fails loudly. Only affects consumers on TS 5.7+ who pass SDK bytes to a BufferSource parameter, and the workaround is a one-line copy.

Problem

Byte fields are typed plain Uint8Array, i.e. Uint8Array<ArrayBufferLike>, which TS 5.7+ lib defs reject wherever BufferSource is required.

Verified on 17.0.0

tsc --strict with lib: ["ES2022", "DOM"]:

declare const e: xdr.ContractCodeEntry;
WebAssembly.compile(e.code);
TS2345: Argument of type 'Uint8Array<ArrayBufferLike>' is not assignable to
        parameter of type 'BufferSource'.
  Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
    Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.

Freighter worked around it with a new Uint8Array(...) copy.

Proposed fix

Type byte fields as Uint8Array<ArrayBuffer>. This is a narrowing, so it is non-breaking for consumers, but it ripples across every byte-returning signature in the XDR codegen — worth sizing before committing.

Also absent from all three migration guides; a line in the Uint8Array guide would cover consumers until the types change.


Reported by @aristidesstaffieri from the Freighter v17 migration (stellar/freighter#2977).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptTypeScript work and type-safety improvementsxdrXDR/types

    Type

    No type

    Projects

    • Status
      Backlog (Not Ready)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions