Repository navigation
Add generic <TArrayBuffer> overloads to TypedArray constructors (#61680) - #65376
Open
Trent Millar (trentmillar) wants to merge 1 commit into
Open
Trent Millar (trentmillar) wants to merge 1 commit into
Trent Millar (trentmillar) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The new typed-array overloads can incorrectly claim SharedArrayBuffer backing for an ordinary ArrayBuffer, allowing calls that type-check but fail at runtime.
No open issues 🎉
What changed in this PR
Addresses #61680 by extending the compiler’s bundled TypedArray declarations so explicit buffer type arguments work with additional constructor forms and subclass super(...) calls.
Changes:
- Adds generic overloads for empty, length, array-like, iterable, and union inputs across TypedArray families.
- Keeps existing non-generic overloads first to preserve default inference and compatibility with #60934.
- Expands compiler regression cases for generic construction and subclassing.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/typedArrayConstructorOverloads.ts |
Adds generic constructor and subclass regression cases. |
tsc/internal/bundled/libs/lib.es5.d.ts |
Adds generic length, array-like, and union overloads. |
tsc/internal/bundled/libs/lib.es2025.float16.d.ts |
Extends Float16Array constructor overloads. |
tsc/internal/bundled/libs/lib.es2020.bigint.d.ts |
Extends both BigInt typed-array constructors. |
tsc/internal/bundled/libs/lib.es2017.typedarrays.d.ts |
Adds generic zero-argument constructors. |
tsc/internal/bundled/libs/lib.es2015.iterable.d.ts |
Adds generic iterable constructors. |
Review effort: Balanced
Author
@microsoft-github-policy-service agree |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #61680
Adds
<TArrayBuffer extends ArrayBufferLike = ArrayBuffer>overloads to the remainingTypedArrayconstructor signatures ((),length,ArrayLike,Iterable, andArrayLike | ArrayBuffer) across the lib files sonew Uint8Array<ArrayBufferLike>(source)andsuper(...)inUint8Array<ArrayBufferLike>subclasses work.Kept the non-generic
TypedArray<ArrayBuffer>overloads first sonew Uint8Array(10)and #60934 aren't affected. Also made sure to hit the 0-arges2017.typedarraysandFloat16Arrayconstructors while I was in there so none of the typed arrays are left out.Checklist:
Backlogmilestonemainbranchnpx hereby testnpx hereby lintnpx hereby check:format