Skip to content

Commit 2fb7cc9

Browse files
anonrigtargos
authored andcommitted
fs: fix typings
PR-URL: #53626 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 87167fa commit 2fb7cc9

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

‎lib/fs.js‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function exists(path, callback) {
254254
validateFunction(callback,'cb');
255255

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

260260
try{
@@ -759,8 +759,8 @@ function readSync(fd, buffer, offsetOrOptions, length, position) {
759759
* @param {(
760760
* err?: Error,
761761
* bytesRead?: number,
762-
* buffers?: ArrayBufferView[];
763-
* ) => any} callback
762+
* buffers?: ArrayBufferView[]
763+
* ) => any} callback
764764
* @returns {void}
765765
*/
766766
functionreadv(fd,buffers,position,callback){
@@ -813,9 +813,9 @@ function readvSync(fd, buffers, position) {
813813
* @param {number | null} [position]
814814
* @param {(
815815
* err?: Error,
816-
* bytesWritten?: number;
816+
* bytesWritten?: number,
817817
* buffer?: Buffer | TypedArray | DataView
818-
* ) => any} callback
818+
* ) => any} callback
819819
* @returns {void}
820820
*/
821821
functionwrite(fd,buffer,offsetOrOptions,length,position,callback){
@@ -891,6 +891,8 @@ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol,
891891
* length?: number;
892892
* position?: number | null;
893893
* }} [offsetOrOptions]
894+
* @param {number} [length]
895+
* @param {number} [position]
894896
* @returns {number}
895897
*/
896898
functionwriteSync(fd,buffer,offsetOrOptions,length,position){
@@ -1084,14 +1086,11 @@ function truncateSync(path, len) {
10841086
}
10851087
// Allow error to be thrown, but still close fd.
10861088
constfd=fs.openSync(path,'r+');
1087-
letret;
1088-
10891089
try{
1090-
ret=fs.ftruncateSync(fd,len);
1090+
fs.ftruncateSync(fd,len);
10911091
}finally{
10921092
fs.closeSync(fd);
10931093
}
1094-
returnret;
10951094
}
10961095

10971096
/**
@@ -1450,8 +1449,8 @@ function readdirSyncRecursive(basePath, options) {
14501449
* }} [options]
14511450
* @param {(
14521451
* err?: Error,
1453-
* files?: string[] | Buffer[] | Dirent[];
1454-
* ) => any} callback
1452+
* files?: string[] | Buffer[] | Dirent[]
1453+
* ) => any} callback
14551454
* @returns {void}
14561455
*/
14571456
functionreaddir(path,options,callback){
@@ -1957,13 +1956,11 @@ function lchmodSync(path, mode) {
19571956

19581957
// Prefer to return the chmod error, if one occurs,
19591958
// but still try to close, and report closing errors if they occur.
1960-
letret;
19611959
try{
1962-
ret=fs.fchmodSync(fd,mode);
1960+
fs.fchmodSync(fd,mode);
19631961
}finally{
19641962
fs.closeSync(fd);
19651963
}
1966-
returnret;
19671964
}
19681965

19691966
/**
@@ -2838,7 +2835,7 @@ function realpath(p, options, callback) {
28382835

28392836
// On windows, check that the root exists. On unix there is no need.
28402837
if(isWindows&&!knownHard.has(base)){
2841-
fs.lstat(base,(err,stats)=>{
2838+
fs.lstat(base,(err)=>{
28422839
if(err)returncallback(err);
28432840
knownHard.add(base);
28442841
LOOP();

‎typings/internalBinding/fs.d.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ declare namespace InternalFSBinding {
5757
}
5858

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

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

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

7575
functioncopyFile(src: StringOrBuffer,dest: StringOrBuffer,mode: number,req: FSReqCallback): void;
7676
functioncopyFile(src: StringOrBuffer,dest: StringOrBuffer,mode: number,req: undefined,ctx: FSSyncContext): void;
@@ -154,7 +154,7 @@ declare namespace InternalFSBinding {
154154
functionmkdir(path: string,mode: number,recursive: false,usePromises: typeofkUsePromises): Promise<void>;
155155

156156
functionopen(path: StringOrBuffer,flags: number,mode: number,req: FSReqCallback<number>): void;
157-
functionopen(path: StringOrBuffer,flags: number,mode: number,req: undefined,ctx: FSSyncContext): number;
157+
functionopen(path: StringOrBuffer,flags: number,mode: number): number;
158158

159159
functionopenFileHandle(path: StringOrBuffer,flags: number,mode: number,usePromises: typeofkUsePromises): Promise<FileHandle>;
160160

@@ -176,6 +176,8 @@ declare namespace InternalFSBinding {
176176
functionreaddir(path: StringOrBuffer,encoding: unknown,withFileTypes: true,usePromises: typeofkUsePromises): Promise<[string[],number[]]>;
177177
functionreaddir(path: StringOrBuffer,encoding: unknown,withFileTypes: false,usePromises: typeofkUsePromises): Promise<string[]>;
178178

179+
functionreadFileUtf8(path: StringOrBuffer,flags: number): string;
180+
179181
functionreadlink(path: StringOrBuffer,encoding: unknown,req: FSReqCallback<string|Buffer>): void;
180182
functionreadlink(path: StringOrBuffer,encoding: unknown,req: undefined,ctx: FSSyncContext): string|Buffer;
181183
functionreadlink(path: StringOrBuffer,encoding: unknown,usePromises: typeofkUsePromises): Promise<string|Buffer>;
@@ -273,6 +275,7 @@ export interface FsBinding {
273275
read: typeofInternalFSBinding.read;
274276
readBuffers: typeofInternalFSBinding.readBuffers;
275277
readdir: typeofInternalFSBinding.readdir;
278+
readFileUtf8: typeofInternalFSBinding.readFileUtf8;
276279
readlink: typeofInternalFSBinding.readlink;
277280
realpath: typeofInternalFSBinding.realpath;
278281
rename: typeofInternalFSBinding.rename;

0 commit comments

Comments
 (0)