Skip to content

Commit 1593855

Browse files
authored
[node] Add NonSharedBuffer/AllowSharedBuffer (DefinitelyTyped#72687)
1 parent 31a25ce commit 1593855

File tree

13 files changed

+41
-29
lines changed

13 files changed

+41
-29
lines changed

types/fs-extra/test/fs-extra-tests.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -868,14 +868,14 @@ fs.readdir(path, { withFileTypes: true }, (err, files) => {
868868
files; // $ExpectType Dirent[]
869869
});
870870

871-
fs.readFile(path); // $ExpectType Promise<Buffer> || Promise<Buffer<ArrayBufferLike>>
871+
fs.readFile(path); // $ExpectType Promise<Buffer> || Promise<Buffer<ArrayBufferLike>> || Promise<NonSharedBuffer>
872872
fs.readFile(path, "utf-8"); // $ExpectType Promise<string>
873873
fs.readFile(path, { encoding: "utf-8" }); // $ExpectType Promise<string>
874-
fs.readFile(path, { flag: "r" }); // $ExpectType Promise<Buffer> || Promise<Buffer<ArrayBufferLike>>
874+
fs.readFile(path, { flag: "r" }); // $ExpectType Promise<Buffer> || Promise<Buffer<ArrayBufferLike>> || Promise<NonSharedBuffer>
875875
// $ExpectType void
876876
fs.readFile(path, (err, data) => {
877877
err; // $ExpectType ErrnoException | null
878-
data; // $ExpectType Buffer || Buffer<ArrayBufferLike>
878+
data; // $ExpectType Buffer || Buffer<ArrayBufferLike> || NonSharedBuffer
879879
});
880880
// $ExpectType void
881881
fs.readFile(path, "utf-8", (err, data) => {
@@ -890,12 +890,12 @@ fs.readFile(path, { encoding: "utf-8" }, (err, data) => {
890890
// $ExpectType void
891891
fs.readFile(path, { flag: "r" }, (err, data) => {
892892
err; // $ExpectType ErrnoException | null
893-
data; // $ExpectType Buffer || Buffer<ArrayBufferLike>
893+
data; // $ExpectType Buffer || Buffer<ArrayBufferLike> || NonSharedBuffer
894894
});
895895
// $ExpectType void
896896
fs.readFile(path, { signal: new AbortController().signal }, (err, data) => {
897897
err; // $ExpectType ErrnoException | null
898-
data; // $ExpectType Buffer || Buffer<ArrayBufferLike>
898+
data; // $ExpectType Buffer || Buffer<ArrayBufferLike> || NonSharedBuffer
899899
});
900900

901901
fs.readlink(path); // $ExpectType Promise<string>

types/node/buffer.buffer.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ declare module "buffer" {
451451
*/
452452
subarray(start?: number, end?: number): Buffer<TArrayBuffer>;
453453
}
454+
type NonSharedBuffer = Buffer<ArrayBuffer>;
455+
type AllowSharedBuffer = Buffer<ArrayBufferLike>;
454456
}
455457
/** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
456458
var SlowBuffer: {

types/node/buffer.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ declare module "buffer" {
122122
* @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
123123
*/
124124
export function resolveObjectURL(id: string): Blob | undefined;
125-
export { Buffer };
125+
export { type AllowSharedBuffer, Buffer, type NonSharedBuffer };
126126
/**
127127
* @experimental
128128
*/

types/node/fs.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,7 @@ declare module "fs" {
26842684
} & Abortable)
26852685
| undefined
26862686
| null,
2687-
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
2687+
callback: (err: NodeJS.ErrnoException | null, data: NonSharedBuffer) => void,
26882688
): void;
26892689
/**
26902690
* Asynchronously reads the entire contents of a file.
@@ -2719,7 +2719,7 @@ declare module "fs" {
27192719
| BufferEncoding
27202720
| undefined
27212721
| null,
2722-
callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
2722+
callback: (err: NodeJS.ErrnoException | null, data: string | NonSharedBuffer) => void,
27232723
): void;
27242724
/**
27252725
* Asynchronously reads the entire contents of a file.
@@ -2728,7 +2728,7 @@ declare module "fs" {
27282728
*/
27292729
export function readFile(
27302730
path: PathOrFileDescriptor,
2731-
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
2731+
callback: (err: NodeJS.ErrnoException | null, data: NonSharedBuffer) => void,
27322732
): void;
27332733
export namespace readFile {
27342734
/**
@@ -2744,7 +2744,7 @@ declare module "fs" {
27442744
encoding?: null | undefined;
27452745
flag?: string | undefined;
27462746
} | null,
2747-
): Promise<Buffer>;
2747+
): Promise<NonSharedBuffer>;
27482748
/**
27492749
* Asynchronously reads the entire contents of a file.
27502750
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2778,7 +2778,7 @@ declare module "fs" {
27782778
})
27792779
| BufferEncoding
27802780
| null,
2781-
): Promise<string | Buffer>;
2781+
): Promise<string | NonSharedBuffer>;
27822782
}
27832783
/**
27842784
* Returns the contents of the `path`.
@@ -2810,7 +2810,7 @@ declare module "fs" {
28102810
encoding?: null | undefined;
28112811
flag?: string | undefined;
28122812
} | null,
2813-
): Buffer;
2813+
): NonSharedBuffer;
28142814
/**
28152815
* Synchronously reads the entire contents of a file.
28162816
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2842,7 +2842,7 @@ declare module "fs" {
28422842
})
28432843
| BufferEncoding
28442844
| null,
2845-
): string | Buffer;
2845+
): string | NonSharedBuffer;
28462846
export type WriteFileOptions =
28472847
| (
28482848
& ObjectEncodingOptions

types/node/ts5.6/buffer.buffer.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ declare module "buffer" {
448448
*/
449449
subarray(start?: number, end?: number): Buffer;
450450
}
451+
type NonSharedBuffer = Buffer;
452+
type AllowSharedBuffer = Buffer;
451453
}
452454
/** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
453455
var SlowBuffer: {

types/node/v18/buffer.buffer.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ declare module "buffer" {
445445
*/
446446
subarray(start?: number, end?: number): Buffer<TArrayBuffer>;
447447
}
448+
type NonSharedBuffer = Buffer<ArrayBuffer>;
449+
type AllowSharedBuffer = Buffer<ArrayBufferLike>;
448450
}
449451
/** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
450452
var SlowBuffer: {

types/node/v18/buffer.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ declare module "buffer" {
112112
* @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
113113
*/
114114
export function resolveObjectURL(id: string): Blob | undefined;
115-
export { Buffer };
115+
export { type AllowSharedBuffer, Buffer, type NonSharedBuffer };
116116
/**
117117
* @experimental
118118
*/

types/node/v18/fs.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ declare module "fs" {
26952695
} & Abortable)
26962696
| undefined
26972697
| null,
2698-
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
2698+
callback: (err: NodeJS.ErrnoException | null, data: NonSharedBuffer) => void,
26992699
): void;
27002700
/**
27012701
* Asynchronously reads the entire contents of a file.
@@ -2730,7 +2730,7 @@ declare module "fs" {
27302730
| BufferEncoding
27312731
| undefined
27322732
| null,
2733-
callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
2733+
callback: (err: NodeJS.ErrnoException | null, data: string | NonSharedBuffer) => void,
27342734
): void;
27352735
/**
27362736
* Asynchronously reads the entire contents of a file.
@@ -2739,7 +2739,7 @@ declare module "fs" {
27392739
*/
27402740
export function readFile(
27412741
path: PathOrFileDescriptor,
2742-
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
2742+
callback: (err: NodeJS.ErrnoException | null, data: NonSharedBuffer) => void,
27432743
): void;
27442744
export namespace readFile {
27452745
/**
@@ -2755,7 +2755,7 @@ declare module "fs" {
27552755
encoding?: null | undefined;
27562756
flag?: string | undefined;
27572757
} | null,
2758-
): Promise<Buffer>;
2758+
): Promise<NonSharedBuffer>;
27592759
/**
27602760
* Asynchronously reads the entire contents of a file.
27612761
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2789,7 +2789,7 @@ declare module "fs" {
27892789
})
27902790
| BufferEncoding
27912791
| null,
2792-
): Promise<string | Buffer>;
2792+
): Promise<string | NonSharedBuffer>;
27932793
}
27942794
/**
27952795
* Returns the contents of the `path`.
@@ -2821,7 +2821,7 @@ declare module "fs" {
28212821
encoding?: null | undefined;
28222822
flag?: string | undefined;
28232823
} | null,
2824-
): Buffer;
2824+
): NonSharedBuffer;
28252825
/**
28262826
* Synchronously reads the entire contents of a file.
28272827
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2853,7 +2853,7 @@ declare module "fs" {
28532853
})
28542854
| BufferEncoding
28552855
| null,
2856-
): string | Buffer;
2856+
): string | NonSharedBuffer;
28572857
export type WriteFileOptions =
28582858
| (
28592859
& ObjectEncodingOptions

types/node/v18/ts5.6/buffer.buffer.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ declare module "buffer" {
443443
*/
444444
subarray(start?: number, end?: number): Buffer;
445445
}
446+
type NonSharedBuffer = Buffer;
447+
type AllowSharedBuffer = Buffer;
446448
}
447449
/** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
448450
var SlowBuffer: {

types/node/v20/buffer.buffer.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ declare module "buffer" {
450450
*/
451451
subarray(start?: number, end?: number): Buffer<TArrayBuffer>;
452452
}
453+
type NonSharedBuffer = Buffer<ArrayBuffer>;
454+
type AllowSharedBuffer = Buffer<ArrayBufferLike>;
453455
}
454456
/** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
455457
var SlowBuffer: {

0 commit comments

Comments
 (0)