oxc-project/oxc · error · OxcDiagnostic

`{builtin_name}` is not a constructor

Error message

`{builtin_name}` is not a constructor

What it means

Lint diagnostic from eslint/no-new-wrappers (not_a_constructor_diagnostic): new was applied to a builtin that is callable but has no constructor form in this context (e.g. new Symbol()/new BigInt()), which throws a TypeError at runtime before any wrapping can happen.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_new_wrappers.rs:23

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

use crate::{
    AstNode,
    context::LintContext,
    fixer::{RuleFix, RuleFixer},
    rule::Rule,
};

fn no_new_wrappers_diagnostic(builtin_name: &str, new_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Do not use `{builtin_name}` as a constructor"))
        .with_help("Remove the `new` operator.")
        .with_label(new_span)
}

fn not_a_constructor_diagnostic(builtin_name: &str, new_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("`{builtin_name}` is not a constructor"))
        .with_help("Remove the `new` operator.")
        .with_label(new_span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow `new` operators with the `String`, `Number`, and `Boolean` objects.
    ///
    /// ### Why is this bad?
    ///
    /// The first problem is that primitive wrapper objects are, in fact,
    /// objects. That means `typeof` will return `"object"` instead of `"string"`,
    /// `"number"`, or `"boolean"`.  The second problem comes with boolean
    /// objects. Every object is truthy, that means an instance of `Boolean`

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Drop new and call the builtin directly, e.g. Symbol(), BigInt(1)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/eslint/no_new_wrappers.rs:23 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/bfc9e8af7793327b. Report an issue: GitHub.