Skip to content

Commit 603c2c5

Browse files
anonrigaduh95
authored andcommitted
fs: fix typings
PR-URL: #53626 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 05058f9 commit 603c2c5

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

lib/fs.js

+13-16
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function exists(path, callback) {
254254
validateFunction(callback, 'cb');
255255

256256
function suppressedCallback(err) {
257-
callback(err ? false : true);
257+
callback(!err);
258258
}
259259

260260
try {
@@ -750,8 +750,8 @@ function readSync(fd, buffer, offsetOrOptions, length, position) {
750750
* @param {(
751751
* err?: Error,
752752
* bytesRead?: number,
753-
* buffers?: ArrayBufferView[];
754-
* ) => any} callback
753+
* buffers?: ArrayBufferView[]
754+
* ) => any} callback
755755
* @returns {void}
756756
*/
757757
function readv(fd, buffers, position, callback) {
@@ -804,9 +804,9 @@ function readvSync(fd, buffers, position) {
804804
* @param {number | null} [position]
805805
* @param {(
806806
* err?: Error,
807-
* bytesWritten?: number;
807+
* bytesWritten?: number,
808808
* buffer?: Buffer | TypedArray | DataView
809-
* ) => any} callback
809+
* ) => any} callback
810810
* @returns {void}
811811
*/
812812
function write(fd, buffer, offsetOrOptions, length, position, callback) {
@@ -882,6 +882,8 @@ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol,
882882
* length?: number;
883883
* position?: number | null;
884884
* }} [offsetOrOptions]
885+
* @param {number} [length]
886+
* @param {number} [position]
885887
* @returns {number}
886888
*/
887889
function writeSync(fd, buffer, offsetOrOptions, length, position) {
@@ -1073,14 +1075,11 @@ function truncateSync(path, len) {
10731075
}
10741076
// Allow error to be thrown, but still close fd.
10751077
const fd = fs.openSync(path, 'r+');
1076-
let ret;
1077-
10781078
try {
1079-
ret = fs.ftruncateSync(fd, len);
1079+
fs.ftruncateSync(fd, len);
10801080
} finally {
10811081
fs.closeSync(fd);
10821082
}
1083-
return ret;
10841083
}
10851084

10861085
/**
@@ -1441,9 +1440,9 @@ function readdirSyncRecursive(basePath, options) {
14411440
* recursive?: boolean;
14421441
* }} [options]
14431442
* @param {(
1444-
* err?: Error;
1445-
* files?: string[] | Buffer[] | Dirent[];
1446-
* ) => any} callback
1443+
* err?: Error,
1444+
* files?: string[] | Buffer[] | Dirent[]
1445+
* ) => any} callback
14471446
* @returns {void}
14481447
*/
14491448
function readdir(path, options, callback) {
@@ -1943,13 +1942,11 @@ function lchmodSync(path, mode) {
19431942

19441943
// Prefer to return the chmod error, if one occurs,
19451944
// but still try to close, and report closing errors if they occur.
1946-
let ret;
19471945
try {
1948-
ret = fs.fchmodSync(fd, mode);
1946+
fs.fchmodSync(fd, mode);
19491947
} finally {
19501948
fs.closeSync(fd);
19511949
}
1952-
return ret;
19531950
}
19541951

19551952
/**
@@ -2814,7 +2811,7 @@ function realpath(p, options, callback) {
28142811

28152812
// On windows, check that the root exists. On unix there is no need.
28162813
if (isWindows && !knownHard.has(base)) {
2817-
fs.lstat(base, (err, stats) => {
2814+
fs.lstat(base, (err) => {
28182815
if (err) return callback(err);
28192816
knownHard.add(base);
28202817
LOOP();

typings/internalBinding/fs.d.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ declare namespace InternalFSBinding {
5757
}
5858

5959
function access(path: StringOrBuffer, mode: number, req: FSReqCallback): void;
60-
function access(path: StringOrBuffer, mode: number, req: undefined, ctx: FSSyncContext): void;
60+
function access(path: StringOrBuffer, mode: number): void;
6161
function access(path: StringOrBuffer, mode: number, usePromises: typeof kUsePromises): Promise<void>;
6262

6363
function chmod(path: string, mode: number, req: FSReqCallback): void;
@@ -70,7 +70,7 @@ declare namespace InternalFSBinding {
7070
function chown(path: string, uid: number, gid: number): void;
7171

7272
function close(fd: number, req: FSReqCallback): void;
73-
function close(fd: number, req: undefined, ctx: FSSyncContext): void;
73+
function close(fd: number): void;
7474

7575
function copyFile(src: StringOrBuffer, dest: StringOrBuffer, mode: number, req: FSReqCallback): void;
7676
function copyFile(src: StringOrBuffer, dest: StringOrBuffer, mode: number, req: undefined, ctx: FSSyncContext): void;
@@ -153,7 +153,7 @@ declare namespace InternalFSBinding {
153153
function mkdir(path: string, mode: number, recursive: false, usePromises: typeof kUsePromises): Promise<void>;
154154

155155
function open(path: StringOrBuffer, flags: number, mode: number, req: FSReqCallback<number>): void;
156-
function open(path: StringOrBuffer, flags: number, mode: number, req: undefined, ctx: FSSyncContext): number;
156+
function open(path: StringOrBuffer, flags: number, mode: number): number;
157157

158158
function openFileHandle(path: StringOrBuffer, flags: number, mode: number, usePromises: typeof kUsePromises): Promise<FileHandle>;
159159

@@ -175,6 +175,8 @@ declare namespace InternalFSBinding {
175175
function readdir(path: StringOrBuffer, encoding: unknown, withFileTypes: true, usePromises: typeof kUsePromises): Promise<[string[], number[]]>;
176176
function readdir(path: StringOrBuffer, encoding: unknown, withFileTypes: false, usePromises: typeof kUsePromises): Promise<string[]>;
177177

178+
function readFileUtf8(path: StringOrBuffer, flags: number): string;
179+
178180
function readlink(path: StringOrBuffer, encoding: unknown, req: FSReqCallback<string | Buffer>): void;
179181
function readlink(path: StringOrBuffer, encoding: unknown, req: undefined, ctx: FSSyncContext): string | Buffer;
180182
function readlink(path: StringOrBuffer, encoding: unknown, usePromises: typeof kUsePromises): Promise<string | Buffer>;
@@ -272,6 +274,7 @@ export interface FsBinding {
272274
read: typeof InternalFSBinding.read;
273275
readBuffers: typeof InternalFSBinding.readBuffers;
274276
readdir: typeof InternalFSBinding.readdir;
277+
readFileUtf8: typeof InternalFSBinding.readFileUtf8;
275278
readlink: typeof InternalFSBinding.readlink;
276279
realpath: typeof InternalFSBinding.realpath;
277280
rename: typeof InternalFSBinding.rename;

0 commit comments

Comments
 (0)