Skip to content

Commit

Permalink
feat(node-fs): enhance writeJson type
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jan 8, 2024
1 parent ab12153 commit 9010c72
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/node-fs/src/write-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {logger} from './common';
import {jsonStringify} from './json';
import {writeFile, writeFileSync} from './write-file';

import type {MaybePromise} from '@alwatr/type-helper';
import type {Dictionary, MaybePromise} from '@alwatr/type-helper';

/**
* Enhanced write json file (Asynchronous).
Expand All @@ -16,7 +16,7 @@ import type {MaybePromise} from '@alwatr/type-helper';
* await writeJsonFile('./file.json', { a:1, b:2, c:3 });
* ```
*/
export function writeJson(path: string, data: unknown, sync?: false): Promise<void>;
export function writeJson<T extends Dictionary>(path: string, data: T, sync?: false): Promise<void>;
/**
* Enhanced write json file (Synchronous).
*
Expand All @@ -28,7 +28,7 @@ export function writeJson(path: string, data: unknown, sync?: false): Promise<vo
* writeJsonFile('./file.json', { a:1, b:2, c:3 }, true);
* ```
*/
export function writeJson(path: string, data: unknown, sync: true): void;
export function writeJson<T extends Dictionary>(path: string, data: T, sync: true): void;
/**
* Enhanced write json file.
*
Expand All @@ -40,7 +40,7 @@ export function writeJson(path: string, data: unknown, sync: true): void;
* await writeJsonFile('./file.json', { a:1, b:2, c:3 }, sync);
* ```
*/
export function writeJson(path: string, data: unknown, sync: boolean): MaybePromise<void>;
export function writeJson<T extends Dictionary>(path: string, data: T, sync: boolean): MaybePromise<void>;
/**
* Enhanced write json file.
*
Expand All @@ -52,7 +52,7 @@ export function writeJson(path: string, data: unknown, sync: boolean): MaybeProm
* await writeJsonFile('./file.json', { a:1, b:2, c:3 });
* ```
*/
export function writeJson(path: string, data: unknown, sync = false): MaybePromise<void> {
export function writeJson<T extends Dictionary>(path: string, data: T, sync = false): MaybePromise<void> {
logger.logMethodArgs?.('writeJson', '...' + path.slice(-32));
const content = flatString(jsonStringify(data));
return sync === true ? writeFileSync(path, content) : writeFile(path, content);
Expand Down

0 comments on commit 9010c72

Please sign in to comment.