-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MockedFunction type doesn't overlap the type of generic functions #1781
Comments
Don't use Hm, I got confused, never mind the above. Still, I don't see types working as you expect in 0.15.2. Are you sure you are not updating typescript at the same time as Vitest? |
If I downgrade to Vitest 0.15.2 but leave everything else the same, the code in the reproduction works. Note that I have to restart the TypeScript server or else restart Visual Studio Code to refresh everything after downgrading the Vitest version. |
This error is because of the mismatch between the return values of both someFunction(). I believe they should have the same return type. I didn't try this code, but have you considered adding the generic to MyMockedInterface's interface MyInterface {
someFunction<T>(a: number): T;
}
interface MyMockedInterface extends MyInterface {
someFunction: <T>(...params: Parameters<MyInterface['someFunction']>) => ReturnType<MockedFunction<() => T>>;
} Notice what I'm doing is, instead of just passing |
Describe the bug
Sometimes we need to extend a TypeScript interface, replacing functions with mocked versions (that are eventually created with
vi.fn()
).This works with most functions, but not with generic functions. It used to work up until Vitest 0.15.2, but broke in 0.16.0 and is still broken as-of 0.20.3.
Reproduction
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: