Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

no-new-wrappers

Disallow new String(), new Number() and new Boolean()

With new, String, Number and Boolean return an object that wraps the value, not the value itself. typeof new String("a") is "object", new Number(1) === 1 is false, and new Boolean(false) is truthy, so the if below always runs.

Without new, the same functions convert a value and return a plain string, number or boolean.

With an oxlint config, --fix rewrites new String("Ada") to "Ada" and new Number(input) to Number(input).

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"no-new-wrappers" = "error" # or "warn"

Examples

Reported:

const enabled = new Boolean(false);

if (enabled) {
  start();
}
const name = new String("Ada");
const port = new Number(input);

Not reported:

const enabled = false;
const name = "Ada";
const port = Number(input);