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

AllowSharedBufferSource definition is incorrect #61480

Open
kainino0x opened this issue Mar 24, 2025 · 0 comments · May be fixed by microsoft/TypeScript-DOM-lib-generator#1944
Open

AllowSharedBufferSource definition is incorrect #61480

kainino0x opened this issue Mar 24, 2025 · 0 comments · May be fixed by microsoft/TypeScript-DOM-lib-generator#1944
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@kainino0x
Copy link

kainino0x commented Mar 24, 2025

⚙ Compilation target

ESNext or any

⚙ Library

ES2024 or newer

Missing / Incorrect Definition

type AllowSharedBufferSource = ArrayBuffer | ArrayBufferView;

should be

type AllowSharedBufferSource = ArrayBuffer | SharedArrayBuffer | ArrayBufferView;

or simply

type AllowSharedBufferSource = BufferSource | SharedArrayBuffer

Sample Code

// Before lib=ES2024, this works, though it seems like it shouldn't.
const x: AllowSharedBufferSource = new SharedArrayBuffer(4);
// The reason is that SharedArrayBuffer is structurally a subtype of ArrayBuffer:
const y: ArrayBuffer = new SharedArrayBuffer(4);
// However when you switch to lib=ES2024+, it (correctly) doesn't work anymore, because
// ArrayBuffer gained some properties that SharedArrayBuffer doesn't have.

Error (playground link):

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

Documentation Link

https://webidl.spec.whatwg.org/#AllowSharedBufferSource

WebIDL:

typedef (ArrayBuffer or SharedArrayBuffer or [AllowShared] ArrayBufferView) AllowSharedBufferSource;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants