oxc-project/oxc · error · OxcDiagnostic

Enforce using `@ts-expect-error` over `@ts-ignore`

Error message

Enforce using `@ts-expect-error` over `@ts-ignore`

What it means

Lint diagnostic from typescript/prefer-ts-expect-error: a @ts-ignore comment was found. Unlike @ts-expect-error, @ts-ignore silently swallows errors even when the suppressed error no longer exists, so typos and stale suppressions go unnoticed.

Source

Thrown at crates/oxc_linter/src/rules/typescript/prefer_ts_expect_error.rs:13

use cow_utils::CowUtils;
use oxc_ast::Comment;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    context::{ContextHost, LintContext},
    rule::Rule,
};

fn prefer_ts_expect_error_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Enforce using `@ts-expect-error` over `@ts-ignore`")
        .with_help("Use \"@ts-expect-error\" to ensure an error is actually being suppressed.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct PreferTsExpectError;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Enforce using @ts-expect-error over @ts-ignore.
    ///
    /// ### Why is this bad?
    ///
    /// TypeScript allows you to suppress all errors on a line by placing a comment starting with @ts-ignore or @ts-expect-error immediately before the erroring line.
    /// The two directives work the same, except @ts-expect-error causes a type error if placed before a line that's not erroring in the first place.
    ///
    /// This means it's easy for @ts-ignores to be forgotten about, and remain in code even after the error they were suppressing is fixed.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace @ts-ignore with @ts-expect-error so TypeScript errors if nothing is actually suppressed
  2. Remove the comment entirely if the underlying error was fixed
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/prefer_ts_expect_error.rs:13 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/aa061e90ae81b11f. Report an issue: GitHub.