Skip to content

Commit 6de27e4

Browse files
committed
Improve the TypeScript types
1 parent adea38e commit 6de27e4

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

index.d.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
export type Reviver = (key: string, value: any) => any;
1+
export type Reviver = (this: unknown, key: string, value: unknown) => unknown;
22
export type BeforeParse = (data: string) => string;
33

44
export interface Options {
55
/**
66
* Applies a function to the JSON string before parsing.
77
*/
8-
beforeParse?: BeforeParse;
8+
readonly beforeParse?: BeforeParse;
9+
910
/**
1011
* Prescribes how the value originally produced by parsing is transformed, before being returned.
1112
* See the [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) for more.
1213
*/
13-
reviver?: Reviver;
14+
readonly reviver?: Reviver;
1415
}
1516

1617
/**
@@ -20,12 +21,14 @@ export interface Options {
2021
*
2122
* @example
2223
*
23-
* import * as loadJsonFile from 'load-json-file';
24+
* import loadJsonFile from 'load-json-file';
2425
*
25-
* const json = loadJsonFile.sync('foo.json');
26-
* //=> {foo: true}
26+
* (async () => {
27+
* const json = await loadJsonFile('foo.json');
28+
* //=> {foo: true}
29+
* })();
2730
*/
28-
export function sync<T = unknown>(filePath: string, options?: Options): T;
31+
export default function loadJsonFile<T = unknown>(filePath: string, options?: Options): Promise<T>;
2932

3033
/**
3134
* Read and parse a JSON file.
@@ -34,11 +37,9 @@ export function sync<T = unknown>(filePath: string, options?: Options): T;
3437
*
3538
* @example
3639
*
37-
* import loadJsonFile from 'load-json-file';
40+
* import * as loadJsonFile from 'load-json-file';
3841
*
39-
* (async () => {
40-
* const json = await loadJsonFile('foo.json');
41-
* //=> {foo: true}
42-
* })();
42+
* const json = loadJsonFile.sync('foo.json');
43+
* //=> {foo: true}
4344
*/
44-
export default function loadJsonFile<T = unknown>(filePath: string, options?: Options): Promise<T>;
45+
export function sync<T = unknown>(filePath: string, options?: Options): T;

0 commit comments

Comments
 (0)