-
Notifications
You must be signed in to change notification settings - Fork 446
Closed
Labels
Description
Summary
Current BufferSource definition is too strict
Expected vs. Actual Behavior
Expected:
type BufferSource = ArrayBufferView<ArrayBuffer> | ArrayBuffer;
Actual:
type BufferSource = ArrayBufferView | ArrayBuffer;
I just recently updated from TypeScript 5.8.3 to 5.9.2 and the only typing error was due to a change in the definition of BufferSource
.
Code example:
...
if (body instanceof ArrayBuffer || body instanceof Uint8Array) {
reqOptions.body = body; // Error here that `Uint8Array<ArrayBufferLike>` can't be assigned
}
...
reqOptions.body
is defined as: BodyInit
.
There doesn't seem to be an easy way to check if the body
value is a ArrayBufferView<ArrayBuffer>
in order to satisfy the BufferSource
definition, since you can't invoke instanceof
on a TypeScript definition.
Seeing that this is a recent change, I wonder if it was a mistake?
Playground Link
No response
Browser Support
- This API is supported in at least two major browser engines (not two Chromium-based browsers).
Have Tried The Latest Releases
- This issue applies to the latest release of TypeScript.
- This issue applies to the latest release of
@types/web
.
Additional Context
No response