← Back to PRs

#16479: fix(test): annotate vitest mock return types to resolve TS2742 portability errors

by colddonkey open 2026-02-14 19:50 View on GitHub →
channel: imessage stale size: S
## Summary - Several shared test harnesses (`monitor.test-harness.ts`, `agent-runner.heartbeat-typing.test-harness.ts`, `agent-runner.memory-flush.test-harness.ts`, `reply.triggers.trigger-handling.test-harness.ts`) export getter functions that return `vi.fn()` mocks without explicit type annotations. - TypeScript infers the return type via the internal `@vitest/spy` path, producing `TS2742: The inferred type cannot be named without a reference to .pnpm/@vitest+spy@...`. This is non-portable and breaks strict type-checking in some environments. - Fix: import `type Mock` from `vitest` and explicitly annotate all affected return types. ## Test plan - [x] `pnpm tsgo` passes cleanly - all TS2742 errors resolved. - [x] No behavioral changes - annotations only. <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds explicit `Mock` type annotations (imported from `vitest`) to exported getter functions across four shared test harness files. This resolves TS2742 portability errors where TypeScript inferred return types via the internal `@vitest/spy` path, which is non-portable across different `node_modules` layouts. - All four harness files (`reply.triggers.trigger-handling.test-harness.ts`, `agent-runner.heartbeat-typing.test-harness.ts`, `agent-runner.memory-flush.test-harness.ts`, `monitor.test-harness.ts`) receive the same treatment: `import { type Mock } from "vitest"` and explicit `: Mock` return type annotations on exported getter functions. - For getters returning objects with multiple mock properties, inline object types with `Mock`-typed fields are used. - No behavioral or runtime changes — annotations only. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge — it contains only type annotations with zero runtime impact. - All changes are type-only annotations on test harness files. No logic, runtime behavior, or test assertions are modified. The `Mock` type from vitest correctly matches the return type of `vi.fn()`. The PR resolves legitimate TS2742 errors as confirmed by the test plan. - No files require special attention. <sub>Last reviewed commit: 80aca37</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs