-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
3.2.0 - Typechecking rejecting expect(value).toEqual(value) in some cases #8081
Copy link
Copy link
Closed
Copy link
Labels
Description
Describe the bug
Starting at 3.2.0 (and possibly due to #7016), the typings of Vitest are rejecting the following code:
function expectMany<T>(value: { enabled: false } | { enable: true; data: T }) {
// In Vitest 3.2:
//
// Argument of type '{ enabled: false; } | { enable: true; data: T; }' is not assignable to parameter of type '{ enabled: false | AsymmetricMatcher<unknown, MatcherState>; } | { enable: true | AsymmetricMatcher<unknown, MatcherState>; data: AsymmetricMatcher<...> | DeeplyAllowMatchers<...>; }'.
// Type '{ enable: true; data: T; }' is not assignable to type '{ enabled: false | AsymmetricMatcher<unknown, MatcherState>; } | { enable: true | AsymmetricMatcher<unknown, MatcherState>; data: AsymmetricMatcher<...> | DeeplyAllowMatchers<...>; }'.
// Type '{ enable: true; data: T; }' is not assignable to type '{ enable: true | AsymmetricMatcher<unknown, MatcherState>; data: AsymmetricMatcher<unknown, MatcherState> | DeeplyAllowMatchers<T>; }'.
// Types of property 'data' are incompatible.
// Type 'T' is not assignable to type 'AsymmetricMatcher<unknown, MatcherState> | DeeplyAllowMatchers<T>'.
// Type 'T' is not assignable to type 'AsymmetricMatcher<unknown, MatcherState>'.ts(2345)
expect(value).toEqual(value);
}Reproduction
Reproduction at https://stackblitz.com/edit/vitest-dev-vitest-jpmhdsdy?file=test%2Fbasic.test.ts
System Info
System:
OS: Windows 11 10.0.26100
CPU: (12) arm64 Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) CPU
Memory: 37.08 GB / 63.49 GB
Binaries:
Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.6.5 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
Edge: Chromium (133.0.3065.69)
npmPackages:
@vitest/coverage-v8: ^3.1.4 => 3.1.4
vitest: ^3.2.0 => 3.2.0Used Package Manager
npm
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.
Reactions are currently unavailable