Skip to content

literalConstructorWrappers

Prefers literal syntax over constructor function calls for primitive values.

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

JavaScript provides built-in constructor functions for creating primitive values: BigInt(), Boolean(), Number(), and String(). While these constructors can coerce values to their respective types, using literal syntax is often more concise and idiomatic when the argument is already a literal value.

This rule flags constructor calls with literal arguments that could be replaced with literal syntax.

AEconsB0valAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0BigI5<3(sp ansty="le--0:#F78C6C;--1:#AA09">821<23sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0valAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0Boole5<3(sp ansty="le--0:#FF6A83;--1:#A248">48tr53<);d ivclassNa="meco"><);d>AEconsB0valAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0Numb5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D<42sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0valAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0Stri5<3(sp ansty="le--0:#F78C6C;--1:#AA09">821<23sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0valAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0Stri5<3(sp ansty="le--0:#FF6A83;--1:#A248">48tr53<);d ivclassNa="meco"><);d>
44AEco61B0v44A098<2123 spans="tyle--0:#C792EA;--1:#88">4<4AEn spans="tyle--0:#D6DEEB;--1:#40">3<23n><;di vdivclass="Nameexpressive-">44AEco61B0v44A48483<;di vdivclass="Nameexpressive-">44AEco61B0v44A09<8242 spans="tyle--0:#D6DEEB;--1:#40">3< 42><;di vdivclass="Nameexpressive-">44AEco61B044A1<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3<23"><;di vdivclass="Nameexpressive-">44AEco61B044A338<34${ spans="tyle--0:#D6DEEB;--1:#40">3F53someVari3<834} spans="tyle--0:#D6DEEB;--1:#40">33<;di vdivclass="Nameexpressive-">44AEco61B0v44A61B0Bi3F53(variab<;di vdivclass="Nameexpressive-">44AEco61B0v44A61B0Boo3F53(variab

This rule is not configurable.

If you prefer the explicit constructor syntax for consistency in your codebase, or if you’re maintaining a codebase where constructor calls are used as a deliberate style choice to make type coercion more explicit, you might prefer to disable this rule.