Skip to content

With TypeScript 5.7 getData returns ArrayBufferLike instead of ArrayBuffer #549

Open
@Scarabol

Description

Thank you all for this great library! I appreciate using it in my project. I just tried to update my TypeScript version from 5.6.3 to 5.7.2.

Starting with Typescript 5.7 typed arrays become generic. See:

This affects for example the type definition of Uint8ArrayWriter

Previously with TypeScript 5.6.3 the following code typed data as ArrayBuffer, but starting with TypeScript > 5.7 data has type ArrayBufferLike.

// TypeScript < 5.7
const data: ArrayBuffer = await entry.getData(new Uint8ArrayWriter());
// TypeScript >= 5.7
const data: ArrayBufferLike = await entry.getData(new Uint8ArrayWriter());

My tsconfig compiler target is and has been set to ES2021.

I'm not sure how this is solved properly. My guess would be to add generic type explicitly to all TypedArrays usages, since they use Uint8Array (Example) actually. Effectively changing type definition here into this:

export class Uint8ArrayWriter extends Writer<Uint8Array<ArrayBuffer>> { }

What do you think?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions