Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions exercises/03.assertions/01.solution.custom-matchers/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ There are two interfaces from `vitest` that I extend using module augmentgation:
- `Assertion<T>`, which controls the matchers returned by calling `expect()`;
- `MatchersDeclaration`, which annotates the matcher declarations passed to `expect.extend()`.

<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exercise text was written before Vitest 3.2 was released. Let's update the text to reflect the proper way of extending the matchers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. It would require multiple changes, as other exercises are still referencing the old vitest version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will go through the remaining mentions of this pattern throughout the workshop and fix them!


```diff ts filename=vitest.setup.ts add=3 remove=2,3 highlight=3
declare module 'vitest' {
- interface Assertion<T = any> extends CustomMatchers<T> {}
- interface MatchersDeclaration extends CustomMatchers {}
+ interface Matchers<T> extends CustomMatchers {}
}
```

This is enough for the `.toMatchSchema()` custom matcher to be recognized by TypeScript:

```ts nonumber nocopy
Expand Down
Loading