Repository navigation
Declare Buffer#subarray in the flow-typed node libdef - #2145
Conversation
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
|
@SamChou19815 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D128877321. |
Metro review: Looks goodRisk: low · Commit: This adds a type-only No findings. Verified
Not run: Jest and benchmarks were not run: the change is a Flow libdef declaration with no runtime or performance effect. The future Flow builtin signature that returns Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
Summary:
X-link: react/react-native#59737
Node's
Buffer#subarrayreturns aBufferthat shares memory with the receiver. The node environment libdef declaresslice(): thisbut nosubarray, sosubarrayresolves toUint8Array#subarrayfrom Flow's builtins. TypeScript's library types that as returningUint8Array<TArrayBuffer>, notthis. Once Flow adopts that signature,buf.subarray(...).toString('hex')and.equals(...)stop checking.Declare
subarray(start?: number, end?: number): thisnext toslice, matching Node's API andtypes/node. Nothing changes under the current builtins.Changelog: [Internal]
Differential Revision: D128877321