Skip to content

Commit 117f04d

Browse files
docs(custom_matchers): make it clear the difference between match interfaces
1 parent 765ea92 commit 117f04d

File tree

1 file changed

+10
-0
lines changed
  • exercises/03.assertions/01.solution.custom-matchers

1 file changed

+10
-0
lines changed

exercises/03.assertions/01.solution.custom-matchers/README.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ There are two interfaces from `vitest` that I extend using module augmentgation:
4444
- `Assertion<T>`, which controls the matchers returned by calling `expect()`;
4545
- `MatchersDeclaration`, which annotates the matcher declarations passed to `expect.extend()`.
4646

47+
<callout-info>Since Vitest 3.2, you can extend the `Matchers` interface to have type-safe assertions in `expect.extend`, `expect().*` and `expect.*` methods at the same time.</callout-info>
48+
49+
```diff ts filename=vitest.setup.ts add=3 remove=2,3 highlight=3
50+
declare module 'vitest' {
51+
- interface Assertion<T = any> extends CustomMatchers<T> {}
52+
- interface MatchersDeclaration extends CustomMatchers {}
53+
+ interface Matchers<T> extends CustomMatchers {}
54+
}
55+
```
56+
4757
This is enough for the `.toMatchSchema()` custom matcher to be recognized by TypeScript:
4858

4959
```ts nonumber nocopy

0 commit comments

Comments
 (0)