Skip to content

Add generic <TArrayBuffer> overloads to TypedArray constructors (#61680) - #65376

Open
Trent Millar (trentmillar) wants to merge 1 commit into
microsoft:mainfrom
trentmillar:fix-61680-generic-typedarray-ctors
Open

Trent Millar (trentmillar) wants to merge 1 commit into
microsoft:mainfrom
trentmillar:fix-61680-generic-typedarray-ctors

Conversation

@trentmillar

Copy link
Copy Markdown

Fixes #61680

Adds <TArrayBuffer extends ArrayBufferLike = ArrayBuffer> overloads to the remaining TypedArray constructor signatures ((), length, ArrayLike, Iterable, and ArrayLike | ArrayBuffer) across the lib files so new Uint8Array<ArrayBufferLike>(source) and super(...) in Uint8Array<ArrayBufferLike> subclasses work.

Kept the non-generic TypedArray<ArrayBuffer> overloads first so new Uint8Array(10) and #60934 aren't affected. Also made sure to hit the 0-arg es2017.typedarrays and Float16Array constructors while I was in there so none of the typed arrays are left out.


Checklist:

  • There is an associated issue in the Backlog milestone
  • Code is up-to-date with the main branch
  • Ran npx hereby test
  • Ran npx hereby lint
  • Ran npx hereby check:format
  • Added/updated compiler tests validating the change

Copilot AI balanced review requested due to automatic review settings November 7, 2026 01:26
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 7, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@trentmillar

Copy link
Copy Markdown
Author

Trent Millar (Trent Millar (@trentmillar)) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Generic TypedArray constructors have only one overload

2 participants