From 855f591992720c49c77a27c28253d3ce896a6913 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Dec 2025 08:49:27 +0000 Subject: [PATCH] Improve type safety for fileHandle and release variables - Add explicit FileHandle type annotation for fileHandle variable - Change fileHandle check from truthy to explicit undefined check - Change release type from null to undefined for better type safety Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --- back/shared/utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/back/shared/utils.ts b/back/shared/utils.ts index 8e51115b..5f12eb23 100644 --- a/back/shared/utils.ts +++ b/back/shared/utils.ts @@ -1,7 +1,7 @@ import { lock } from 'proper-lockfile'; import os from 'os'; import path from 'path'; -import { writeFile, open, chmod } from 'fs/promises'; +import { writeFile, open, chmod, FileHandle } from 'fs/promises'; import { fileExist } from '../config/util'; import Logger from '../loaders/logger'; @@ -23,14 +23,14 @@ export async function writeFileWithLock( // Ensure file exists before locking if (!(await fileExist(filePath))) { - let fileHandle; + let fileHandle: FileHandle | undefined; try { fileHandle = await open(filePath, 'w'); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to create file ${filePath}: ${errorMessage}`); } finally { - if (fileHandle) { + if (fileHandle !== undefined) { try { await fileHandle.close(); } catch (closeError) { @@ -42,7 +42,7 @@ export async function writeFileWithLock( } const lockfilePath = getUniqueLockPath(filePath); - let release: (() => Promise) | null = null; + let release: (() => Promise) | undefined; try { release = await lock(filePath, {