# prefer-expect-type-of

Rule `vitest/prefer-expect-type-of`. Enforce using `expect(...).toBeTypeOf(...)` instead of `expect(typeof ...).toBe(...)`

- Source: vitest
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1796 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vitest/prefer-expect-type-of` | no | safe | package `@vitest/eslint-plugin` | [docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-expect-type-of.md) |
| Oxlint | `vitest/prefer-expect-type-of` | no | safe | plugin `vitest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-expect-type-of.html) |

## Code examples

### Incorrect: the rule reports this

```ts
import { test, expect } from 'vitest'

test('type checking', () => {
  expect(typeof 'hello').toBe('string')
  expect(typeof 42).toBe('number')
  expect(typeof true).toBe('boolean')
  expect(typeof {}).toBe('object')
  expect(typeof (() => {})).toBe('function')
  expect(typeof Symbol()).toBe('symbol')
  expect(typeof 123n).toBe('bigint')
  expect(typeof undefined).toBe('undefined')
})
```

### Correct: the rule accepts this

```ts
import { test, expect } from 'vitest'

test('type checking', () => {
  expect('hello').toBeTypeOf('string')
  expect(42).toBeTypeOf('number')
  expect(true).toBeTypeOf('boolean')
  expect({}).toBeTypeOf('object')
  expect(() => {}).toBeTypeOf('function')
  expect(Symbol()).toBeTypeOf('symbol')
  expect(123n).toBeTypeOf('bigint')
  expect(undefined).toBeTypeOf('undefined')
})
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import vitest from "@vitest/eslint-plugin";

export default [
  {
    plugins: { vitest },
    rules: {
      "vitest/prefer-expect-type-of": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "vitest"
  ],
  "rules": {
    "vitest/prefer-expect-type-of": "error"
  }
}
```

## Related rules

- [vitest/prefer-expect-resolves](https://lintradar.dev/rules/vitest/prefer-expect-resolves.md): Enforce using `expect().resolves` over `expect(await ...)` syntax
- [vitest/prefer-import-in-mock](https://lintradar.dev/rules/vitest/prefer-import-in-mock.md): Prefer dynamic import in mock
- [vitest/prefer-expect-assertions](https://lintradar.dev/rules/vitest/prefer-expect-assertions.md): Enforce using expect assertions instead of callbacks
- [vitest/prefer-mock-promise-shorthand](https://lintradar.dev/rules/vitest/prefer-mock-promise-shorthand.md): Enforce mock resolved/rejected shorthands for promises
- [vitest/prefer-each](https://lintradar.dev/rules/vitest/prefer-each.md): Enforce using `each` rather than manual loops
- [vitest/prefer-mock-return-shorthand](https://lintradar.dev/rules/vitest/prefer-mock-return-shorthand.md): Prefer mock return shorthands

---

Web page: https://lintradar.dev/rules/vitest/prefer-expect-type-of. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
