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

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

Open
petamoriken opened this issue Oct 6, 2024 · 2 comments · May be fixed by #60150
Open

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

petamoriken opened this issue Oct 6, 2024 · 2 comments · May be fixed by #60150
Assignees
Labels
Fix Available A PR has been opened for this issue

Comments

@petamoriken
Copy link
Contributor

⚙ 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

@petamoriken
Copy link
Contributor Author

petamoriken commented Oct 6, 2024

FYI: Restricting subclassing support in built-in methods – Data (2024-10 TC39 meeting slide)

@milkcask
Copy link

milkcask commented Oct 7, 2024

Somewhat related: #60142
Same approach, using string instead of the exact well-known tags.

@petamoriken thanks for the FYI !

@RyanCavanaugh RyanCavanaugh added Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Needs Investigation This issue needs a team member to investigate its status. and removed Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Oct 7, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.7.0 milestone Oct 7, 2024
@typescript-bot typescript-bot added Fix Available A PR has been opened for this issue labels Oct 14, 2024
@rbuckton rbuckton removed the Needs Investigation This issue needs a team member to investigate its status. label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue
Projects
None yet
5 participants