{"record":{"id":"1f84a6ceb50f2287","repo":"oxc-project/oxc","slug":"type-assertions-should-be-done-using-tobetypeof","errorCode":null,"errorMessage":"Type assertions should be done using `toBeTypeOf`.","messagePattern":"Type assertions should be done using `toBeTypeOf`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/prefer_expect_type_of.rs","lineNumber":16,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, UnaryOperator},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    context::LintContext,\n    rule::Rule,\n    utils::{MemberExpressionElement, PossibleJestNode, parse_expect_jest_fn_call},\n};\n\nfn prefer_expect_type_of_diagnostic(span: Span, help: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Type assertions should be done using `toBeTypeOf`.\")\n        .with_help(format!(\"Substitute the assertion with `{help}`.\"))\n        .with_label(span)\n        .with_note(\"https://vitest.dev/api/expect#tobetypeof\")\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferExpectTypeOf;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforce using [`toBeTypeOf`](https://vitest.dev/api/expect#tobetypeof) instead of `expect(typeof ...).toBe(...)`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// `expect(typeof value).toBe(type)` works but is awkward and produces poor failure messages.\n    /// Vitest's built-in `toBeTypeOf` matcher performs the same `typeof` comparison with a clearer API and better error output.\n    ///","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/prefer_expect_type_of.rs#L1-L34","documentation":"Emitted by the vitest/prefer-expect-type-of rule at an expectation that asserts a type with `typeof x === 'string'` (or similar comparison) instead of vitest's `toBeTypeOf` matcher. It fires because `toBeTypeOf` is the idiomatic, more readable vitest type assertion.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/prefer_expect_type_of.rs:16 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `expect(typeof x).toBe('string')` / `expect(typeof x === 'string').toBe(true)` with `expect(x).toBeTypeOf('string')`"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}