Skip to content

Declare Buffer#subarray in the flow-typed node libdef - #59737

Merged
meta-codesync[bot] merged 1 commit into
mainfrom
export-D128877321
Nov 2, 2026
Merged

meta-codesync[bot] merged 1 commit into
mainfrom
export-D128877321

Conversation

@SamChou19815

Copy link
Copy Markdown
Member

Summary:
Node's Buffer#subarray returns a Buffer that shares memory with the receiver. The node environment libdef declares slice(): this but no subarray, so subarray resolves to Uint8Array#subarray from Flow's builtins. TypeScript's library types that as returning Uint8Array<TArrayBuffer>, not this. Once Flow adopts that signature, buf.subarray(...).toString('hex') and .equals(...) stop checking.

Declare subarray(start?: number, end?: number): this next to slice, matching Node's API and types/node. Nothing changes under the current builtins.

Changelog: [Internal]

Differential Revision: D128877321

Summary:
Node's `Buffer#subarray` returns a `Buffer` that shares memory with the receiver. The node environment libdef declares `slice(): this` but no `subarray`, so `subarray` resolves to `Uint8Array#subarray` from Flow's builtins. TypeScript's library types that as returning `Uint8Array<TArrayBuffer>`, not `this`. Once Flow adopts that signature, `buf.subarray(...).toString('hex')` and `.equals(...)` stop checking.

Declare `subarray(start?: number, end?: number): this` next to `slice`, matching Node's API and `types/node`. Nothing changes under the current builtins.

Changelog: [Internal]

Differential Revision: D128877321
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 1, 2026
@meta-codesync

meta-codesync Bot commented Nov 1, 2026

Copy link
Copy Markdown

@SamChou19815 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D128877321.

@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Nov 1, 2026
meta-codesync Bot pushed a commit to react/metro that referenced this pull request Nov 2, 2026
Summary:
X-link: react/react-native#59737

Node's `Buffer#subarray` returns a `Buffer` that shares memory with the receiver. The node environment libdef declares `slice(): this` but no `subarray`, so `subarray` resolves to `Uint8Array#subarray` from Flow's builtins. TypeScript's library types that as returning `Uint8Array<TArrayBuffer>`, not `this`. Once Flow adopts that signature, `buf.subarray(...).toString('hex')` and `.equals(...)` stop checking.

Declare `subarray(start?: number, end?: number): this` next to `slice`, matching Node's API and `types/node`. Nothing changes under the current builtins.

Changelog: [Internal]

Differential Revision: D128877321

Pull Request resolved: #2145
@meta-codesync
meta-codesync Bot merged commit 7cd2f00 into main Nov 2, 2026
110 of 111 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @SamChou19815 in 7cd2f00

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 2, 2026
@SamChou19815
SamChou19815 deleted the export-D128877321 branch November 2, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants