Open
Description
Describe the bug
I have a mock for an instance of a class that is basically an object type as a Partial<>
from the original class.
When using spyOn
on a method of this instance, TypeScript cannot infer the return type and shows Property 'mockReturnValue' does not exist on type 'never'
.
When I do not use Partial<>
but just declare the object it works fine.
However, I want the type safety when declaring the mock, therefore I am using Partial<>
. I am just switching from Jest where this exact setup works fine.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-6wdpqq8p?file=test%2Fpartial.test.ts
System Info
System:
OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
CPU: (14) x64 Intel(R) Core(TM) Ultra 7 155U
Memory: 6.34 GB / 23.23 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 22.9.0 - ~/.nvm/versions/node/v22.9.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.9.0/bin/yarn
npm: 10.8.3 - ~/.nvm/versions/node/v22.9.0/bin/npm
npmPackages:
vitest: ^3.0.8 => 3.0.8
Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.