Made a few utility types for writeFile options

This commit is contained in:
Kir_Antipov 2023-01-25 17:51:19 +00:00
parent 88b6d0607a
commit 79519efc22

View file

@ -0,0 +1,32 @@
import { writeFileSync } from "node:fs";
import { writeFile } from "node:fs/promises";
/**
* Options that can be used with `fs.writeFile()` to write a file asynchronously.
*/
export type AsyncWriteFileOptions = Parameters<typeof writeFile>[2];
/**
* Options that can be used with `fs.writeFileSync()` to write a file synchronously.
*/
export type SyncWriteFileOptions = Parameters<typeof writeFileSync>[2];
/**
* All possible options that can be passed to `fs.writeFile()` and `fs.writeFileSync()`.
*/
export type WriteFileOptions = AsyncWriteFileOptions | SyncWriteFileOptions;
/**
* Object-style options that can be used with `fs.writeFile()` to write a file asynchronously.
*/
export type AsyncWriteFileOptionsObject = Exclude<AsyncWriteFileOptions, string>;
/**
* Object-style options that can be used with `fs.writeFileSync()` to write a file synchronously.
*/
export type SyncWriteFileOptionsObject = Exclude<SyncWriteFileOptions, string>;
/**
* All possible object-style options that can be passed to `fs.writeFile()` and `fs.writeFileSync()`.
*/
export type WriteFileOptionsObject = AsyncWriteFileOptionsObject | SyncWriteFileOptionsObject;