fix(types): ArrayBuffer.prototype.resize returns void - #32484
Pablosinyores wants to merge 1 commit into
Conversation
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.
WalkthroughThe return type of ChangesArrayBuffer.resize return type correction
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
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. Comment |
|
Gentle ping on this one. |
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.
|
Triage note: this is not on main yet (checked at f426a8e), the branch still merges cleanly, and One small thing for whoever merges: the description says |
|
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 |
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>
|
Dedupe note, to settle the two notes above. #39608 fixes #26868 as a whole ( This PR stays open. It still applies to main on its own and passes |
|
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 |
What does this PR do?
ArrayBuffer.prototype.resize()resizes the buffer in place and returnsundefinedper the ECMAScript spec, butbun-typesdeclared it as returningArrayBuffer:This both gives the wrong type at runtime (the return is
undefined) and conflicts with TypeScript's own lib andcore-js-types, which type the return asvoid(reported in #26868). Corrected tovoid.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.tsthat the result ofresize()isvoid. Verified withtscagainst the packedbun-typesdeclarations: the fixture type-checks with this change and fails on the previous declaration (Type 'ArrayBuffer' is not assignable to type 'void').