Skip to content

Commit 71e90be

Browse files
kgryteaayush0325
authored andcommitted
fix: update return types
1 parent 1b7341a commit 71e90be

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/node_modules/@stdlib/fs/read-json/docs/types/index.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ type Reviver = ( key: string, value: any ) => any;
5555
* Callback invoked upon reading a file.
5656
*
5757
* @param err - error object
58-
* @param file - file contents
58+
* @param data - file contents
5959
*/
60-
type Callback = ( err: Error | null, file: Buffer | string ) => void;
60+
type Callback<T> = ( err: Error | null, data: T ) => void;
6161

6262
/**
6363
* Interface for reading a file as JSON.
@@ -85,7 +85,7 @@ interface ReadJSON {
8585
* console.dir( data );
8686
* }
8787
*/
88-
( file: string | Buffer | number, options: Options | string, clbk: Callback ): void;
88+
<T = unknown>( file: string | Buffer | number, options: Options | string, clbk: Callback<T> ): void;
8989

9090
/**
9191
* Asynchronously reads a file as JSON.
@@ -105,7 +105,7 @@ interface ReadJSON {
105105
* console.dir( data );
106106
* }
107107
*/
108-
( file: string | Buffer | number, clbk: Callback ): void;
108+
<T = unknown>( file: string | Buffer | number, clbk: Callback<T> ): void;
109109

110110
/**
111111
* Synchronously reads a file as JSON.
@@ -127,7 +127,7 @@ interface ReadJSON {
127127
* }
128128
* console.dir( out );
129129
*/
130-
sync( file: string | Buffer | number, options?: Options | string ): string | Error;
130+
sync<T = unknown>( file: string | Buffer | number, options?: Options | string ): T | Error;
131131
}
132132

133133
/**

lib/node_modules/@stdlib/fs/read-json/docs/types/test.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@
1818

1919
import readJSON = require( './index' );
2020

21-
const onLoad = ( error: Error | null, file: string | Buffer ) => {
22-
if ( error || !file ) {
21+
/**
22+
* Callback function.
23+
*
24+
* @param error - error object
25+
* @param data - results
26+
*/
27+
function onLoad( error: Error | null, data?: Array<string> | Buffer ): void {
28+
if ( error || !data ) {
2329
throw error;
2430
}
25-
};
31+
}
2632

2733

2834
// TESTS //
@@ -105,9 +111,9 @@ const onLoad = ( error: Error | null, file: string | Buffer ) => {
105111
readJSON( 'C:\\foo\\bar\\baz\\package.json' ); // $ExpectError
106112
}
107113

108-
// Attached to main export is a `sync` method which returns a string or an error...
114+
// Attached to main export is a `sync` method which returns results or an error...
109115
{
110-
readJSON.sync( 'package.json' ); // $ExpectType string | Error
116+
readJSON.sync<Array<string>>( 'package.json' ); // $ExpectType Error | string[]
111117
}
112118

113119
// The compiler throws an error if the `sync` method is provided a first argument which is not a string, buffer, or file descriptor...

0 commit comments

Comments
 (0)