Skip to content

fix(types): ArrayBuffer.prototype.resize returns void - #32484

Closed
Pablosinyores wants to merge 1 commit into
oven-sh:mainfrom
Pablosinyores:bun-types-arraybuffer-resize-void
Closed

Pablosinyores wants to merge 1 commit into
oven-sh:mainfrom
Pablosinyores:bun-types-arraybuffer-resize-void

Conversation

@Pablosinyores

@Pablosinyores Pablosinyores commented Jun 18, 2026 •

Copy link
Copy Markdown

What does this PR do?

ArrayBuffer.prototype.resize() resizes the buffer in place and returns undefined per the ECMAScript spec, but bun-types declared it as returning ArrayBuffer:

resize(byteLength: number): ArrayBuffer; // wrong

This both gives the wrong type at runtime (the return is undefined) and conflicts with TypeScript's own lib and core-js-types, which type the return as void (reported in #26868). Corrected to void.

Part of #26868. #39608 covers the whole issue and includes this change.

How did you verify your code works?

Added an assertion in test/integration/bun-types/fixture/array-buffer.ts that the result of resize() is void. Verified with tsc against the packed bun-types declarations: the fixture type-checks with this change and fails on the previous declaration (Type 'ArrayBuffer' is not assignable to type 'void').

ArrayBuffer.prototype.resize() mutates the buffer in place and returns
undefined per the ECMAScript spec, but bun-types declared it as returning
ArrayBuffer. This also conflicts with TypeScript's own lib and core-js-types,
which correctly type the return as void.
@Pablosinyores
Pablosinyores requested a review from alii as a code owner June 18, 2026 09:52

@claude claude Bot 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The return type of ArrayBuffer.prototype.resize in packages/bun-types/globals.d.ts is corrected from ArrayBuffer to void, aligning with the ECMAScript specification. A corresponding type-checking fixture is added to assert the void return type at compile time.

Changes

ArrayBuffer.resize return type correction

Layer / File(s) Summary
ArrayBuffer.resize signature and type fixture
packages/bun-types/globals.d.ts, test/integration/bun-types/fixture/array-buffer.ts
resize(byteLength: number) return type changed from ArrayBuffer to void in the interface declaration. A fixture adds a const resizeResult: void = buffer.resize(...) assertion with comments referencing the ECMAScript spec to verify the corrected type at compile time.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: correcting the return type of ArrayBuffer.prototype.resize from ArrayBuffer to void.
Linked Issues check ✅ Passed The PR successfully addresses the primary objective from #26868 by correcting ArrayBuffer.prototype.resize to return void per ECMAScript spec, aligning with TypeScript and core-js-types. Issue #39 is unrelated to this PR's scope.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the ArrayBuffer.prototype.resize return type issue identified in #26868. The type declaration update and test fixture are both focused on this specific objective.
Description check ✅ Passed The description includes both required sections and clearly explains the change, specification basis, issue context, and verification steps.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Pablosinyores

Copy link
Copy Markdown
Author

Gentle ping on this one. ArrayBuffer.prototype.resize returns undefined per the spec (ECMAScript 25.1.6.x), but the type currently says it returns ArrayBuffer, so chained .resize(n).byteLength typechecks today and shouldn't. Small, isolated change in bun-types with a fixture asserting the corrected void. @dylan-conway would you be able to trigger the build / take a look when you have a moment? Happy to rebase if anything shifted with the recent bun-types CI work.

robobun pushed a commit that referenced this pull request Aug 13, 2026
grow() resizes the buffer in place and returns undefined
(https://tc39.es/ecma262/#sec-sharedarraybuffer.prototype.grow), but
bun-types declared it as returning the SharedArrayBuffer. Because
bun-types merges its own SharedArrayBuffer interface into the lib
declaration, its signature is the one a grow(n) call resolves to, so
chaining off the result type-checked even though it is undefined at
runtime.

Companion to the same correction for ArrayBuffer.prototype.resize in
#32484; the two merge independently.
@robobun

robobun commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Triage note: this is not on main yet (checked at f426a8e), the branch still merges cleanly, and bun test test/integration/bun-types/bun-types.test.ts passes with it applied. #36505, which had copied this fix into a batch, has been cut down to just the matching SharedArrayBuffer.prototype.grow() line; the two merge independently in either order, so this PR is the one to land for resize(). Thanks for the fix and for the patience.

One small thing for whoever merges: the description says Closes #26868, but that issue also covers the Promise.withResolvers resolve(value?: ...) signature, which is still unchanged on main, so this PR only fixes the resize() half of it. Probably better as a plain reference so the issue stays open for the other half.

@robobun

robobun commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Update to the note above: #39608 now carries this change. It aligns the whole block of ECMAScript declarations in globals.d.ts with the TypeScript lib files for #26868, and resize() is part of that block (resize(newByteLength?: number): void, as in lib.es2024.arraybuffer.d.ts). The commit there credits you as co-author. If #39608 lands first, this PR can be closed; if this one lands first, #39608 rebases onto it.

robobun added a commit that referenced this pull request Aug 19, 2026
Mock<T> is now T & MockInstance<T>, and mock() and jest.fn() get an overload
with a required implementation parameter, so a mock of a generic or overloaded
function keeps its call signatures (#38037).

The WebSocket "error" event is an ErrorEvent, which is what the runtime
dispatches (#36329).

Bun.WebView declares goBack() and goForward(), the names the runtime
exposes, instead of back() and forward() (#30754).

The global ReadableStream interface extends the same interface as the
node:stream/web augmentation, so text(), json(), bytes() and blob() exist
when lib.dom.d.ts is loaded too (#29401). #31757 proposed the same
extension of the global interface, but placed it at the top level of
overrides.d.ts, which is a module, so it never reached the global
interface.

Map and WeakMap declare getOrInsert() and getOrInsertComputed() with the
signatures from lib.esnext.collection.d.ts (#27380).

The ECMAScript additions in globals.d.ts are grouped into one region and
each signature matches the TypeScript lib file it duplicates. This changes
ArrayBuffer.resize() (the change from #32484) and SharedArrayBuffer.grow()
(they return void), Promise.withResolvers() (it returns
PromiseWithResolvers<T>), Promise.try(), Array.fromAsync() and
Uint8Array.setFromBase64() (its second parameter is an options object, a
number throws at runtime). A fixture re-declares the standard signatures
the way core-js does and fails on any drift (#26868).

bun-types imports from undici-types, so it declares it as a dependency. A
test checks that every package the .d.ts files import from is declared
(#22805).

The FormData iterator types (#27194) are not part of this commit. #34264
fixes them.

Co-authored-by: Pablosinyores <nikhilbajaj0182@gmail.com>
Co-authored-by: fenley <49503866+godfengliang@users.noreply.github.com>
@robobun

robobun commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Dedupe note, to settle the two notes above. #39608 fixes #26868 as a whole (resize() is one line of the block it aligns with the TypeScript lib files) and keeps this change with your co-author credit. So that one PR is linked to the issue, the Closes #26868 line in this description is now a plain reference to the issue. Nothing else in the description changed. The issue also covers Promise.withResolvers(), so it would have stayed open after this PR in any case.

This PR stays open. It still applies to main on its own and passes bun test test/integration/bun-types/bun-types.test.ts, and it is the smaller change if a maintainer prefers to take it first. Whichever of the two lands second resolves the one resize() line (this PR keeps the parameter name, #39608 uses the lib's newByteLength?: number).

@robobun

robobun commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Thank you for this fix. The maintainers asked to land all of the open bun-types fixes in one PR, #39608, and its first commit carries the resize() change with you credited as co-author (the parameter also becomes newByteLength?: number to match lib.es2024.arraybuffer.d.ts). Closing this one in its favor.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants