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

Type 'ArrayBufferLike' is not assignable to type 'BlobPart'. #60579

Closed
Yonom opened this issue Nov 24, 2024 · 3 comments
Closed

Type 'ArrayBufferLike' is not assignable to type 'BlobPart'. #60579

Yonom opened this issue Nov 24, 2024 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Yonom
Copy link

Yonom commented Nov 24, 2024

🔎 Search Terms

ArrayBufferLike BlobPart SharedArrayBuffer ES2024

🕗 Version & Regression Information

  • This changed between versions 5.7.2 and 5.6.3
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play/?target=11&ts=5.7.2#code/MYewdgzgLgBFICEA2IBGMC8MAUATAhlPgFwwCqAlmFABwCCATg-gJ4A0cLADgKanQMqAcwCUmAHwwA3jABQMGAx5QArgzAwwPAO4xkabAG0CRAHSoVAM0s8GAXQ4yo3HjAC+IgNyy3QA

💻 Code

When targetting ES2024, the following code throws a type error:

const toBlob = (data: Uint8Array, type: string) => { 
  return new Blob([data.buffer], { type });
}

🙁 Actual behavior

Type 'ArrayBufferLike' is not assignable to type 'BlobPart'.
  Type 'SharedArrayBuffer' is not assignable to type 'BlobPart'.
    Type 'SharedArrayBuffer' is missing the following properties from type 'ArrayBuffer': resizable, resize, detached, transfer, transferToFixedLength

🙂 Expected behavior

Backwards compatibility with ES2023

Additional information about the issue

No response

@jcalz
Copy link
Contributor

jcalz commented Nov 25, 2024

The TS 5.7 release notes and #59417 explain what's going on here. If you want a Uint8Array whose buffer property is a suitable BlobPart you'll have to ask for it explicitly like

const toBlob = (data: Uint8Array<ArrayBuffer>, type: string) => { 
  return new Blob([data.buffer], { type });
}

Playground link

And of course that might have to propagate throughout your code base. Maybe the TS team has a recommendation for how to proceed in general with this sort of thing; the release notes only mention updating node.

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2024
@MonstraG
Copy link

MonstraG commented Dec 2, 2024

Yea, it would be very nice to see some recommendations. @types/node is updated to 22.10.1, and I'm hitting a similar issue with

https://www.typescriptlang.org/play/?target=99#code/MYewdgzgLgBARgQwE4C4YEElIQTwEICuAZkQKZIAyAlgNakwC8MYpA7jAKpVhQAcm2HAAoAlAG4gA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants