Skip to content

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

Open
SamChou19815 wants to merge 1 commit into
mainfrom
export-D128877321
Open

SamChou19815 wants to merge 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.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant