Skip to content

Commit 3dd85c2

Browse files
update info on buffer (#1689)
1 parent 4eb855e commit 3dd85c2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

runtime/fundamentals/node.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,18 @@ import { Buffer } from "node:buffer";
574574
const buf = new Buffer(5, "0");
575575
```
576576
577+
For TypeScript users needing Node.js-specific types like `BufferEncoding`, these
578+
are available through the `NodeJS` namespace when using `@types/node`:
579+
580+
```ts title="buffer-types.ts"
581+
/// <reference types="npm:@types/node" />
582+
583+
// Now you can use NodeJS namespace types
584+
function writeToBuffer(data: string, encoding: NodeJS.BufferEncoding): Buffer {
585+
return Buffer.from(data, encoding);
586+
}
587+
```
588+
577589
Prefer using
578590
[`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
579591
or other

0 commit comments

Comments
 (0)