Skip to content

Commit 40ac71f

Browse files
test(utils): type the hoisted fs actuals by the callback return type
The drift control's hoisted holder cast undefined straight to two overloaded function types, which tsc rejects (TS2352 at safeWriteJson.stagingDirectory.spec.ts:9 and :10). The holder is now typed by the hoisted callback's return type instead, so there is no cast on undefined and no double assertion. Measured with the worktree's own node_modules (split-1833/u7 got a real pnpm install this round, and @roo-code/types now resolves to that worktree's packages/types): tsc -p tsconfig.json exit 0 with 0 errors; vitest run of safeWriteJson.test.ts, safeWriteJson.lockKey.spec.ts and safeWriteJson.stagingDirectory.spec.ts exit 0, 3 files, 36 passed, 4 skipped.
1 parent 504af84 commit 40ac71f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎src/utils/__tests__/safeWriteJson.stagingDirectory.spec.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import { safeWriteJson } from "../safeWriteJson"
55

66
// Capture the actual implementations before the mock factory wraps them, so a mocked realpath or
77
// stat can delegate to the real one without recursing into itself.
8-
const actuals = vi.hoisted(() => ({
9-
realpath: undefined as (typeof import("fs/promises"))["realpath"],
10-
stat: undefined as (typeof import("fs/promises"))["stat"],
11-
}))
8+
// Typed by the hoisted callback's return type rather than by a cast on undefined: the target types
9+
// are overloaded function types, and casting undefined straight to them is what tsc rejects (TS2352).
10+
const actuals = vi.hoisted(
11+
(): { realpath?: (typeof import("fs/promises"))["realpath"]; stat?: (typeof import("fs/promises"))["stat"] } => ({
12+
realpath: undefined,
13+
stat: undefined,
14+
}),
15+
)
1216

1317
vi.mock("fs/promises", async () => {
1418
const actual = await vi.importActual<typeof import("fs/promises")>("fs/promises")

0 commit comments

Comments
 (0)