-
Notifications
You must be signed in to change notification settings - Fork 404
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
Vitest typings are broken in 6.5.0 #629
Comments
thanks for noticing it as for long term solution I'm still in progress of investigation, but it seems the problem is in here what I see in interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
<T>(actual: T, message?: string): Assertion<T>;
extend: (expects: MatchersObject) => void;
anything: () => any;
any: (constructor: unknown) => any;
getState: () => MatcherState;
setState: (state: Partial<MatcherState>) => void;
not: AsymmetricMatchersContaining;
}
interface AsymmetricMatchersContaining {
stringContaining: (expected: string) => any;
objectContaining: <T = any>(expected: T) => any;
arrayContaining: <T = unknown>(expected: Array<T>) => any;
stringMatching: (expected: string | RegExp) => any;
closeTo: (expected: number, precision?: number) => any;
} Here i see that we can validate it by just removing import {type expect} from 'vitest'
import {type TestingLibraryMatchers} from './matchers'
declare module 'vitest' {
interface Assertion<T = any>
extends TestingLibraryMatchers<
ReturnType<typeof expect.stringContaining>,
T
> {}
} I didn't have much spare time recently, hence replied here only a week after issue is opened, but i'll try to dive deeper on I'll update on my findings here alongside (hopefully) with a PR with long-term solution |
fwiw I've opened #636 which should resolve the TypeScript error |
@all-contributors please add @billyjanitsch for bug |
I've put up a pull request to add @billyjanitsch! 🎉 |
🎉 This issue has been resolved in version 6.6.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@testing-library/jest-dom
version: 6.5.0node
version: 20.15.1jest
(orvitest
) version: Vitest 2.0.5npm
(oryarn
) version: npm 10.8.2Relevant code or config:
See reproduction repo below.
What you did:
Followed the setup instructions for Vitest in the readme.
What happened:
Running the TS checker in a minimal environment produces the following errors:
Reproduction:
I've isolated the problem to a barebones setup:
https://github.com/billyjanitsch/vitest-jest-dom-types
Problem description:
#612 (which was released in 6.5.0) updated the typings for Vitest in a way that seems to be incompatible with Vitest's own definitions. I understand that that PR was an attempt to align the typings with the official recommendations, but it seems to be broken.
Suggested solution:
I'd suggest reverting #612 until it can be tested and fixed.
For a long-term fix, this is just a guess based on the TS error and looking at the type defs, but I think the problem might be related to importing
type expect
fromvitest
and then using that type when extending thevitest
module type. This recursive self-reference might not be allowed/supported by the TS compiler.cc @vorant94
The text was updated successfully, but these errors were encountered: