@types/node 16.0.3 → 16.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/fs/promises.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  declare module 'fs/promises' {
2
- import { Abortable } from 'events';
3
- import { Stream } from 'stream';
2
+ import { Abortable } from 'node:events';
3
+ import { Stream } from 'node:stream';
4
4
  import {
5
5
  Stats,
6
6
  BigIntStats,
@@ -14,12 +14,38 @@ declare module 'fs/promises' {
14
14
  Dirent,
15
15
  OpenDirOptions,
16
16
  Dir,
17
- BaseEncodingOptions,
17
+ ObjectEncodingOptions,
18
18
  BufferEncodingOption,
19
19
  OpenMode,
20
20
  Mode,
21
21
  WatchOptions,
22
- } from 'fs';
22
+ } from 'node:fs';
23
+
24
+ interface FlagAndOpenMode {
25
+ mode?: Mode | undefined;
26
+ flag?: OpenMode | undefined;
27
+ }
28
+
29
+ interface FileReadResult<T extends ArrayBufferView> {
30
+ bytesRead: number;
31
+ buffer: T;
32
+ }
33
+
34
+ interface FileReadOptions<T extends ArrayBufferView = Buffer> {
35
+ /**
36
+ * @default `Buffer.alloc(0xffff)`
37
+ */
38
+ buffer?: T;
39
+ /**
40
+ * @default 0
41
+ */
42
+ offset?: number | null;
43
+ /**
44
+ * @default `buffer.byteLength`
45
+ */
46
+ length?: number | null;
47
+ position?: number | null;
48
+ }
23
49
 
24
50
  // TODO: Add `EventEmitter` close
25
51
  interface FileHandle {
@@ -38,7 +64,7 @@ declare module 'fs/promises' {
38
64
  * If `mode` is a string, it is parsed as an octal integer.
39
65
  * If `flag` is not supplied, the default of `'a'` is used.
40
66
  */
41
- appendFile(data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode | undefined, flag?: OpenMode | undefined } | BufferEncoding | null): Promise<void>;
67
+ appendFile(data: string | Uint8Array, options?: ObjectEncodingOptions & FlagAndOpenMode | BufferEncoding | null): Promise<void>;
42
68
 
43
69
  /**
44
70
  * Asynchronous fchown(2) - Change ownership of a file.
@@ -69,8 +95,8 @@ declare module 'fs/promises' {
69
95
  * @param length The number of bytes to read.
70
96
  * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
71
97
  */
72
- read<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Promise<{ bytesRead: number, buffer: TBuffer }>;
73
-
98
+ read<T extends ArrayBufferView>(buffer: T, offset?: number | null, length?: number | null, position?: number | null): Promise<FileReadResult<T>>;
99
+ read<T extends ArrayBufferView = Buffer>(options?: FileReadOptions<T>): Promise<FileReadResult<T>>;
74
100
  /**
75
101
  * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
76
102
  * The `FileHandle` must have been opened for reading.
@@ -93,7 +119,7 @@ declare module 'fs/promises' {
93
119
  * @param options An object that may contain an optional flag.
94
120
  * If a flag is not provided, it defaults to `'r'`.
95
121
  */
96
- readFile(options?: BaseEncodingOptions & { flag?: OpenMode | undefined } | BufferEncoding | null): Promise<string | Buffer>;
122
+ readFile(options?: ObjectEncodingOptions & { flag?: OpenMode | undefined } | BufferEncoding | null): Promise<string | Buffer>;
97
123
 
98
124
  /**
99
125
  * Asynchronous fstat(2) - Get file status.
@@ -147,7 +173,7 @@ declare module 'fs/promises' {
147
173
  * If `mode` is a string, it is parsed as an octal integer.
148
174
  * If `flag` is not supplied, the default of `'w'` is used.
149
175
  */
150
- writeFile(data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode | undefined, flag?: OpenMode | undefined } & Abortable | BufferEncoding | null): Promise<void>;
176
+ writeFile(data: string | Uint8Array, options?: ObjectEncodingOptions & FlagAndOpenMode & Abortable | BufferEncoding | null): Promise<void>;
151
177
 
152
178
  /**
153
179
  * See `fs.writev` promisified version.
@@ -249,7 +275,7 @@ declare module 'fs/promises' {
249
275
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
250
276
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
251
277
  */
252
- function readdir(path: PathLike, options?: BaseEncodingOptions & { withFileTypes?: false | undefined } | BufferEncoding | null): Promise<string[]>;
278
+ function readdir(path: PathLike, options?: ObjectEncodingOptions & { withFileTypes?: false | undefined } | BufferEncoding | null): Promise<string[]>;
253
279
 
254
280
  /**
255
281
  * Asynchronous readdir(3) - read a directory.
@@ -263,21 +289,21 @@ declare module 'fs/promises' {
263
289
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
264
290
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
265
291
  */
266
- function readdir(path: PathLike, options?: BaseEncodingOptions & { withFileTypes?: false | undefined } | BufferEncoding | null): Promise<string[] | Buffer[]>;
292
+ function readdir(path: PathLike, options?: ObjectEncodingOptions & { withFileTypes?: false | undefined } | BufferEncoding | null): Promise<string[] | Buffer[]>;
267
293
 
268
294
  /**
269
295
  * Asynchronous readdir(3) - read a directory.
270
296
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
271
297
  * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
272
298
  */
273
- function readdir(path: PathLike, options: BaseEncodingOptions & { withFileTypes: true }): Promise<Dirent[]>;
299
+ function readdir(path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true }): Promise<Dirent[]>;
274
300
 
275
301
  /**
276
302
  * Asynchronous readlink(2) - read value of a symbolic link.
277
303
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
278
304
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
279
305
  */
280
- function readlink(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
306
+ function readlink(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
281
307
 
282
308
  /**
283
309
  * Asynchronous readlink(2) - read value of a symbolic link.
@@ -291,7 +317,7 @@ declare module 'fs/promises' {
291
317
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
292
318
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
293
319
  */
294
- function readlink(path: PathLike, options?: BaseEncodingOptions | string | null): Promise<string | Buffer>;
320
+ function readlink(path: PathLike, options?: ObjectEncodingOptions | string | null): Promise<string | Buffer>;
295
321
 
296
322
  /**
297
323
  * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
@@ -380,7 +406,7 @@ declare module 'fs/promises' {
380
406
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
381
407
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
382
408
  */
383
- function realpath(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
409
+ function realpath(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
384
410
 
385
411
  /**
386
412
  * Asynchronous realpath(3) - return the canonicalized absolute pathname.
@@ -394,14 +420,14 @@ declare module 'fs/promises' {
394
420
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
395
421
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
396
422
  */
397
- function realpath(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
423
+ function realpath(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
398
424
 
399
425
  /**
400
426
  * Asynchronously creates a unique temporary directory.
401
427
  * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
402
428
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
403
429
  */
404
- function mkdtemp(prefix: string, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
430
+ function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
405
431
 
406
432
  /**
407
433
  * Asynchronously creates a unique temporary directory.
@@ -415,7 +441,7 @@ declare module 'fs/promises' {
415
441
  * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
416
442
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
417
443
  */
418
- function mkdtemp(prefix: string, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
444
+ function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
419
445
 
420
446
  /**
421
447
  * Asynchronously writes data to a file, replacing the file if it already exists.
@@ -433,7 +459,7 @@ declare module 'fs/promises' {
433
459
  function writeFile(
434
460
  path: PathLike | FileHandle,
435
461
  data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | Stream,
436
- options?: BaseEncodingOptions & { mode?: Mode | undefined, flag?: OpenMode | undefined } & Abortable | BufferEncoding | null
462
+ options?: ObjectEncodingOptions & { mode?: Mode | undefined, flag?: OpenMode | undefined } & Abortable | BufferEncoding | null
437
463
  ): Promise<void>;
438
464
 
439
465
  /**
@@ -451,7 +477,7 @@ declare module 'fs/promises' {
451
477
  function appendFile(
452
478
  path: PathLike | FileHandle,
453
479
  data: string | Uint8Array,
454
- options?: BaseEncodingOptions & { mode?: Mode | undefined, flag?: OpenMode | undefined } | BufferEncoding | null
480
+ options?: ObjectEncodingOptions & FlagAndOpenMode | BufferEncoding | null,
455
481
  ): Promise<void>;
456
482
 
457
483
  /**
@@ -479,7 +505,7 @@ declare module 'fs/promises' {
479
505
  * @param options An object that may contain an optional flag.
480
506
  * If a flag is not provided, it defaults to `'r'`.
481
507
  */
482
- function readFile(path: PathLike | FileHandle, options?: BaseEncodingOptions & Abortable & { flag?: OpenMode | undefined } | BufferEncoding | null): Promise<string | Buffer>;
508
+ function readFile(path: PathLike | FileHandle, options?: ObjectEncodingOptions & Abortable & { flag?: OpenMode | undefined } | BufferEncoding | null): Promise<string | Buffer>;
483
509
 
484
510
  function opendir(path: string, options?: OpenDirOptions): Promise<Dir>;
485
511