close

prefer-expect-type-of

Added in v0.8.2

Configuration

rslint.config.ts
import { defineConfig, rstestPlugin } from '@rslint/core';

export default defineConfig([
  rstestPlugin.configs.recommended,
  {
    rules: {
      'rstest/prefer-expect-type-of': 'error',
    },
  },
]);

Rule Details

Prefers toBeTypeOf over comparing typeof with a string. The dedicated matcher makes the assertion's intent clearer and gives a better failure message.

The rule supports regular and soft Rstest assertions.

Incorrect

expect(typeof value).toBe('string');

Correct

expect(value).toBeTypeOf('string');

Autofix

Rewrites the assertion to toBeTypeOf, leaving the expect factory, a message argument, and the modifier chain untouched.