Skip to content

Use string literal type in ArrayBuffer's Symbol.toStringTag #60149

Closed
@petamoriken

Description

@petamoriken

⚙ Compilation target

ES2023

⚙ Library

N/A

Missing / Incorrect Definition

For ES2023 or lower targets, it is acceptable to assign SharedArrayBuffer to an ArrayBuffer type. On the other hand, the reverse is not possible because Symbol.toStringTag of SharedArrayBuffer is a string literal type.

This problem can be solved by making Symbol.toStringTag of ArrayBuffer a string literal type. Set, Map, and Promise use the string type for library compatibility (#19006), while ArrayBuffer is not intended to be extended by the user, and indeed Symbol.species support for InitializeTypedArrayFromTypedArray has been removed (tc39/ecma262#2719), so there should be no problem.

This issue was reported by #59417 and has been addressed by making TypedArrays generic for the ES2024 target.

Sample Code

// ES2023 or lower targets, no type error
const buffer: ArrayBuffer = new SharedArrayBuffer(256);

Documentation Link

No response

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions