memfs
memfs copied to clipboard
Wrong type for readFile in .promises
Compare
readFile(id: TFileHandle, options?: IReadFileOptions | string): Promise<TDataOut>;
to Node's
function readFile(path: PathLike | FileHandle, options?: { encoding?: null, flag?: OpenMode } & Abortable | null): Promise<Buffer>;
function readFile(path: PathLike | FileHandle, options: { encoding: BufferEncoding, flag?: OpenMode } & Abortable | BufferEncoding): Promise<string>;
function readFile(path: PathLike | FileHandle, options?: BaseEncodingOptions & Abortable & { flag?: OpenMode } | BufferEncoding | null): Promise<string | Buffer>;
For a case when BufferEncoding
is present, result type has to be string
. Why don't just copy (or reuse, if memfs
is a drop-in replacement) typings from @types/node
?
UPD.
declare const promises: Omit<
(typeof import("fs"))["promises"],
"read" | "write" | "ftruncate" | "rm" | "fdatasync" | "fsync" | "fchmod" | "lutimes" | "fchown" | "futimes" | "opendir" | "watch"
>;
should do the trick
I'm running into this issue too
Typecasting with as string
for now to work around