Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With TypeScript 5.7 getData returns ArrayBufferLike instead of ArrayBuffer #549

Open
Scarabol opened this issue Dec 23, 2024 · 1 comment

Comments

@Scarabol
Copy link

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?

@gildas-lormeau
Copy link
Owner

Thank for the info. Actually, I don't use TS for development and I was not aware of this issue. I wonder how to deal with that. I guess somehow I would need to publish 2 index.d.ts files?

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

No branches or pull requests

2 participants