Description
@testing-library/jest-dom
version: 6.5.0node
version: 20.15.1jest
(orvitest
) version: Vitest 2.0.5npm
(oryarn
) version: npm 10.8.2
Relevant 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:
node_modules/@testing-library/jest-dom/types/vitest.d.ts:7:32 - error TS2339: Property 'stringContaining' does not exist on type 'ExpectStatic'.
7 ReturnType<typeof expect.stringContaining>,
~~~~~~~~~~~~~~~~
node_modules/@testing-library/jest-dom/types/vitest.d.ts:10:13 - error TS2310: Type 'AsymmetricMatchersContaining' recursively references itself as a base type.
10 interface AsymmetricMatchersContaining
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@testing-library/jest-dom/types/vitest.d.ts:12:32 - error TS2339: Property 'stringContaining' does not exist on type 'ExpectStatic'.
12 ReturnType<typeof expect.stringContaining>,
~~~~~~~~~~~~~~~~
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
from vitest
and then using that type when extending the vitest
module type. This recursive self-reference might not be allowed/supported by the TS compiler.
cc @vorant94