From d12ce35332d625cbc7d94a4a8b7a5b5d2004bcf0 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Sun, 1 Nov 2026 09:43:16 -0800 Subject: [PATCH] Declare `Buffer#subarray` in the flow-typed node libdef 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`, 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 --- flow-typed/environment/node.js | 1 + 1 file changed, 1 insertion(+) diff --git a/flow-typed/environment/node.js b/flow-typed/environment/node.js index 61a4206c427..959f77da012 100644 --- a/flow-typed/environment/node.js +++ b/flow-typed/environment/node.js @@ -118,6 +118,7 @@ declare class Buffer extends Uint8Array { readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number; slice(start?: number, end?: number): this; + subarray(start?: number, end?: number): this; swap16(): Buffer; swap32(): Buffer; swap64(): Buffer;