Skip to content

Comments

docs: update Testing Types docs to use non-deprecated expect-type API and add toMatchObjectType documentation#8397

Merged
sheremet-va merged 4 commits intomainfrom
copilot/fix-8387
Aug 9, 2025
Merged

docs: update Testing Types docs to use non-deprecated expect-type API and add toMatchObjectType documentation#8397
sheremet-va merged 4 commits intomainfrom
copilot/fix-8387

Conversation

Copy link
Contributor

Copilot AI commented Aug 6, 2025

The Testing Types documentation was using the deprecated toMatchTypeOf matcher from expect-type, which has been deprecated since v1.2.0 in favor of toExtend. This PR updates all documentation to use the current API and adds comprehensive documentation for toMatchObjectType.

Changes Made

Updated deprecated API usage:

  • Replaced toMatchTypeOf with toExtend in code examples across /docs/guide/testing-types.md and /docs/guide/features.md
  • Added deprecation warning to toMatchTypeOf documentation with clear migration guidance
  • Fixed test file /test/config/test/config-types.test-d.ts to use current API

Added new documentation:

  • Complete toExtend section with examples and usage patterns
  • New toMatchObjectType section with detailed documentation, examples, and usage guidelines
  • Clear comparison between toExtend and toMatchObjectType showing when to use each

API Changes Documented

Before:

expectTypeOf(mount).parameter(0).toMatchTypeOf<{ name: string }>()

After:

expectTypeOf(mount).parameter(0).toExtend<{ name: string }>()
// or for stricter object type checking:
expectTypeOf(mount).parameter(0).toMatchObjectType<{ name: string }>()

The toMatchObjectType matcher provides stricter checking for object types and is recommended when working with plain objects as it's more likely to catch issues like readonly properties. For union types and complex types, toExtend should be used instead.

Fixes #8387.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@netlify
Copy link

netlify bot commented Aug 6, 2025

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 6d64421
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/68977bbb0f0daa0008774369
😎 Deploy Preview https://deploy-preview-8397--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI changed the title [WIP] Update Testing Types docs to use non-deprecated API docs: update Testing Types docs to use non-deprecated expect-type API Aug 6, 2025
Copilot AI requested a review from sheremet-va August 6, 2025 15:31
@outslept
Copy link
Contributor

outslept commented Aug 6, 2025

Could you also add documentation to.toMatchObjectType() as well? It was introduced alongside .toExtend() in expect-type v1.2.0 and is the preferred choice for object types. Don't think I can edit copilot's branch. This is my suggestion:

## toMatchObjectType

- **Type:** `<T>() => void`

This matcher performs a strict check on object types, ensuring that the expected type matches the provided object type. It's stricter than [`toExtend`](#toextend) and is the recommended choice when working with object types as it's more likely to catch issues like readonly properties.

```ts
import { expectTypeOf } from 'vitest'

expectTypeOf({ a: 1, b: 2 }).toMatchObjectType<{ a: number }>() // preferred
expectTypeOf({ a: 1, b: 2 }).toExtend<{ a: number }>()         // works but less strict

// Supports nested object checking
const user = {
  name: 'John',
  address: { city: 'New York', zip: '10001' }
}
expectTypeOf(user).toMatchObjectType<{ name: string; address: { city: string } }>()
```

::: warning
This matcher only works with plain object types. It will fail for union types and other complex types. For those cases, use [`toExtend`](#toextend) instead.
:::

@sheremet-va
Copy link
Member

@copilot add documentation to.toMatchObjectType() as well. It was introduced alongside .toExtend() in expect-type v1.2.0. suggestion from @outslept:

## toMatchObjectType

- **Type:** `<T>() => void`

This matcher performs a strict check on object types, ensuring that the expected type matches the provided object type. It's stricter than [`toExtend`](#toextend) and is the recommended choice when working with object types as it's more likely to catch issues like readonly properties.

```ts
import { expectTypeOf } from 'vitest'

expectTypeOf({ a: 1, b: 2 }).toMatchObjectType<{ a: number }>() // preferred
expectTypeOf({ a: 1, b: 2 }).toExtend<{ a: number }>()         // works but less strict

// Supports nested object checking
const user = {
  name: 'John',
  address: { city: 'New York', zip: '10001' }
}
expectTypeOf(user).toMatchObjectType<{ name: string; address: { city: string } }>()
```

::: warning
This matcher only works with plain object types. It will fail for union types and other complex types. For those cases, use [`toExtend`](#toextend) instead.
:::

Copy link
Contributor Author

Copilot AI commented Aug 7, 2025

@copilot add documentation to.toMatchObjectType() as well. It was introduced alongside .toExtend() in expect-type v1.2.0. suggestion from @outslept:

...

Added the toMatchObjectType documentation as requested. The new section includes complete examples, usage guidance, and a warning about its limitations with union types. The documentation follows the same structure as other matchers and is positioned logically after the toExtend section. Commit: 0862250

Copilot AI changed the title docs: update Testing Types docs to use non-deprecated expect-type API docs: update Testing Types docs to use non-deprecated expect-type API and add toMatchObjectType documentation Aug 7, 2025
Copilot AI requested a review from sheremet-va August 7, 2025 14:57
@outslept
Copy link
Contributor

outslept commented Aug 7, 2025

If this goes in, we can close #7589 too.

cc @mmkal — apologies for the ping; feel free to ignore. If you prefer different terminology or spot any inaccuracies, a note would be appreciated.

@mmkal
Copy link
Contributor

mmkal commented Aug 8, 2025

Looks good to me - thanks!

@sheremet-va sheremet-va marked this pull request as ready for review August 9, 2025 16:39
import { expectTypeOf } from 'vitest'

expectTypeOf({ a: 1, b: 2 }).toMatchObjectType<{ a: number }>() // preferred
expectTypeOf({ a: 1, b: 2 }).toExtend<{ a: number }>() // works but less strict
Copy link
Member

Choose a reason for hiding this comment

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

@copilot the lint is failing. Fix all lint issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the linting error by removing extra spaces in the code comment. Commit: 6d64421

Copilot AI requested a review from sheremet-va August 9, 2025 16:48
@sheremet-va sheremet-va merged commit 7ff9c67 into main Aug 9, 2025
11 of 14 checks passed
@sheremet-va sheremet-va deleted the copilot/fix-8387 branch August 9, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Testing Types docs to use non-deprecated API

4 participants