From 7347ad9c866996a971d20fd6fc78b1d2c29fcbb8 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Mon, 8 Jan 2024 20:46:53 +0330 Subject: [PATCH] feat(node-fs): enhance writeJson type --- packages/node-fs/src/write-json.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/node-fs/src/write-json.ts b/packages/node-fs/src/write-json.ts index 262fda70..897aafab 100644 --- a/packages/node-fs/src/write-json.ts +++ b/packages/node-fs/src/write-json.ts @@ -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). @@ -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; +export function writeJson(path: string, data: T, sync?: false): Promise; /** * Enhanced write json file (Synchronous). * @@ -28,7 +28,7 @@ export function writeJson(path: string, data: unknown, sync?: false): Promise(path: string, data: T, sync: true): void; /** * Enhanced write json file. * @@ -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; +export function writeJson(path: string, data: T, sync: boolean): MaybePromise; /** * Enhanced write json file. * @@ -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 { +export function writeJson(path: string, data: T, sync = false): MaybePromise { logger.logMethodArgs?.('writeJson', '...' + path.slice(-32)); const content = flatString(jsonStringify(data)); return sync === true ? writeFileSync(path, content) : writeFile(path, content);