Suggesting R = unknown
for custom matchers makes asymmetric matchers error
#7731
Labels
documentation
Improvements or additions to documentation
Describe the bug
Here's how Vitest docs recommend declaring types for custom matchers.
While this works with symmetric matchers (
expect(a).toBeFoo()
), when you apply this to an asymmetric one, theunknown
return type of the matcher will result in a type error.Suggested solutions
any
instead ofunknown
. The two are not the same and are not interchangeable[1]. Here, it looks likeany
may be a better fit.In fact, I think it should've been
any
from the start. The matcher itself cannot infer or guarantee a type of the value (that'd be out of its scope). The best it can do is beanything
.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-2narajwa?file=vite.config.ts,test%2Fbasic.test.ts&initialPath=__vitest__/
Go to
test/basic.test.ts
and see the type error when asserting on thes
property. It must not be there.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: