oxc-project/oxc · error · OxcDiagnostic

Do not use `{type_name}` as a type

Error message

Do not use `{type_name}` as a type

What it means

Raised by typescript/no-restricted-types when a type annotation uses a type name listed in the rule's restricted list (default: String, Number, Boolean, Symbol, Object), with no custom message configured.

Source

Thrown at crates/oxc_linter/src/rules/typescript/no_restricted_types.rs:28

};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

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

fn no_restricted_types_diagnostic(
    type_name: &str,
    message: Option<&str>,
    span: Span,
) -> OxcDiagnostic {
    let msg = message.unwrap_or_default();
    if msg.is_empty() {
        OxcDiagnostic::warn(format!("Do not use `{type_name}` as a type"))
            .with_help("This type is restricted from being used.")
            .with_label(span)
    } else {
        OxcDiagnostic::warn(format!("Do not use `{type_name}` as a type"))
            .with_help(msg.to_string())
            .with_label(span)
    }
}

/// Built from config once: O(1) lookups by normalized name + keyword fast flags.
#[derive(Debug, Clone, Default)]
struct RestrictedTypesIndex {
    /// Key = type name with all whitespace removed (matches TS-ESLint `removeSpaces`).
    /// Value = (display name for diagnostics, ban config).
    by_name: FxHashMap<Box<str>, (Box<str>, BanConfigValue)>,
    /// True if any banned name needs a full source span (e.g. `Banned<any>`, not `[]`/`{}`).
    has_generic_or_complex_keys: bool,
    /// True if any banned name can match a qualified type name (e.g. `NS.Banned`).

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Use the primitive lowercase form: string, number, boolean, symbol.
  2. Use a specific object/interface type instead of Object.
  3. Remove the type from the rule configuration if it should be allowed.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/no_restricted_types.rs:28 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/d1af2e7908e16002. Report an issue: GitHub.