Skip to content

5.9.0-beta - Type 'Buffer<ArrayBuffer>' is not assignable to type 'ArrayBuffer' #62109

Closed

Description

🔎 Search Terms

ArrayBuffer
Type 'Buffer' is not assignable to type 'ArrayBuffer'.`
5.9.0-beta

🕗 Version & Regression Information

https://stackblitz.com/edit/vitejs-vite-ymeftbvq?file=tsconfig.json

With @types/node set to 20.19.4 as a constant, this code below is fine in 5.8.3

const test: ArrayBuffer = Buffer.from('test', 'utf-8');

errors with error TS2322: Type 'Buffer<ArrayBuffer>' is not assignable to type 'ArrayBuffer'. in 5.9.0-beta

  • This changed between versions 5.8.3 and 5.9.0-beta

It appears to be fixable by switching to

const test: ArrayBuffer = Buffer.from('test', 'utf-8').buffer

⏯ Playground Link

https://stackblitz.com/edit/vitejs-vite-ymeftbvq?file=tsconfig.json

🙁 Actual behavior

Failed typechecking

🙂 Expected behavior

Expected this to pass

Additional information about the issue

No response

Activity

  1. jakebailey commented on Jul 23, 2025

    @jakebailey
    Member

    Given Buffer isn't an ArrayBuffer, I'm pretty sure this is intentional. https://nodejs.org/api/buffer.html#bufbuffer is an ArrayBuffer.

    Unless I'm really missing something.

  2. maschwenk commented on Jul 23, 2025

    @maschwenk
    ContributorAuthor

    Based on a private Discord discussion, this appears to be intentional, though I am curious if this should be flagging with @types/node 20.19.x. Also just curious which commit/PR changed this, I tried scanning through v5.8.3...v5.9-beta but was having trouble finding.

  3. jakebailey commented on Jul 23, 2025

    @jakebailey
    Member

    #61647 and related PRs.

    All currently supported Node types pass with the last 10 versions of TS, so I would think this would behave correctly.

  4. Renegade334 commented on Jul 24, 2025

    @Renegade334
    Contributor

    The quirk of the array buffer view (TypedArray/DataView) interfaces being assignable to ArrayBuffer was a complete accident previously. Mistaking array buffer views for ArrayBuffers is a very common mishap, and one that the checker was previously blind to.

    The divergence between the ArrayBuffer and array buffer view interfaces has existed since TS5.7, but only previously applied if targeting es2024+. Since #60150, it now applies universally.

  5. petamoriken commented on Jul 24, 2025

    @petamoriken
    Contributor

    Node.js's Buffer does NOT inherit from ArrayBuffer, but rather inherits from Uint8Array, so I think the problem is due to incorrect usage in the first place.

    const test: Uint8Array<ArrayBuffer> = Buffer.from('test', 'utf-8');
  6. maschwenk commented on Jul 24, 2025

    @maschwenk
    ContributorAuthor

    Thanks all! Appreciate all that context!

  7. locked as resolved and limited conversation to collaborators on Oct 22, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions