From 0ddf619edc126bc34158b0db8f225b8ea5089bdf Mon Sep 17 00:00:00 2001 From: Mika Vilpas Date: Sat, 15 Feb 2025 17:45:44 +0200 Subject: [PATCH] fix: make the return type of scan function nullable Issue ===== Looking at the return type of `scan()`, it is not nullable, which hints at it throwing an error. However, in practice it does not throw an error and returns `null` when the path does not exist. Solution ======== Make the return type of `scan()` nullable to indicate that the caller should check if it succeeded. --- source/lib/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lib/index.ts b/source/lib/index.ts index 7818825..7c1fb77 100644 --- a/source/lib/index.ts +++ b/source/lib/index.ts @@ -1150,7 +1150,7 @@ async function _parseTreeAsync(children: Dree[], prefix: string, options: ParseO * @return {object} The directory tree as a Dree object * @template Node The type of the tree object, which can be extended and changed by the onFile and onDir functions. */ -export function scan(path: string, options?: ScanOptions, onFile?: Callback, onDir?: Callback): Node { +export function scan(path: string, options?: ScanOptions, onFile?: Callback, onDir?: Callback): Node | null { const opt = mergeScanOptions(options); const root = resolvePath(path, opt); const result = _scan(root, root, 0, opt, onFile, onDir);