Skip to content

Commit f0c2f49

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

File tree

1 file changed

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

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ 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+
> [!tip]
48+
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.
49+
50+
```diff ts filename=vitest.setup.ts add=3 remove=2,3 highlight=3
51+
declare module 'vitest' {
52+
- interface Assertion<T = any> extends CustomMatchers<T> {}
53+
- interface MatchersDeclaration extends CustomMatchers {}
54+
+ interface Matchers<T> extends CustomMatchers {}
55+
}
56+
```
57+
4758
This is enough for the `.toMatchSchema()` custom matcher to be recognized by TypeScript:
4859

4960
```ts nonumber nocopy

0 commit comments

Comments
 (0)