Skip to content

builtinConstructorNews

Enforces using new for constructors that require it, and disallows new for primitive coercion functions.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Many built-in JavaScript objects have tricky behaviors around the new keyword. Some only work as expected when called with new, while others cannot or should not be called with new. This rule enforces consistent and safe calling of built-in JavaScript constructors using or not using new.

Specifically, this rule enforces using new for following built-in constructors:

This rule disallows using new for following built-in constructors:

Using new with primitive coercion functions creates object wrappers that can cause unexpected behavior in comparisons and type checks.

AEconsB0liAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0Arr5<3(sp ansty="le--0:#F78C6C;--1:#AA09">82<10sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0nAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0Da53(<);d ivclassNa="meco"><);d>AEconsB0mAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0M53(<[[sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dk1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<, sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dval1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53]]<);d ivclassNa="meco"><);d>AEconsB0sAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0Stri5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dhel1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0nAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0Numb5<3(sp ansty="le--0:#F78C6C;--1:#AA09">82<42sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEco61B044A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B0A309<8210 spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><10)><;di vdivclass="Nameexpressive-">44AEco61B<0now spans="tyle--0:#C792EA;--1:#88">44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B03F5<3() ;divclass="Name"><;di vdivclass="Nameexpressive-">44AEco61B<0map spans="tyle--0:#C792EA;--1:#88">44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B<0Map spans="tyle--0:#D6DEEB;--1:#40">3F5<3([[ spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dv1<111" spans="tyle--0:#D6DEEB;--1:#40">3F53<]]) ;divclass="Name"><]])><;di vdivclass="Nameexpressive-">44AEco61B<0str spans="tyle--0:#C792EA;--1:#88">44A61B0St3F53(val<;di vdivclass="Nameexpressive-">44AEco61B<0num spans="tyle--0:#C792EA;--1:#88">44A61B0Nu3F53(val

This rule is not configurable.

If you intentionally use object wrappers for primitives (e.g., new String()) for specific purposes like adding properties to a string value, you may disable this rule. For example, if you intentionally manage JavaScript primitives in a legacy codebase that does not adhere to common modern conventions, this rule may be counterproductive for you.