Reports inconsistent placement of type arguments in constructor calls.
✅ This rule is included in the ts stylistic and stylisticStrict presets.
When constructing a generic class, type arguments can be specified on either the left-hand side (as a type annotation) or the right-hand side (as part of the constructor call).
This rule ensures that type arguments appear consistently on one side of the declaration.
Keeping to one side consistently improves code readability.
The rule never reports when there are type arguments on both sides, or neither side of the declaration.
It also doesn’t report if the names of the type annotation and the constructor don’t match.
With the default "constructor" style:
AEconsB0m7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>11MAB0striAE<, sp ansty="le--0:#C5E478;--1:#3B61">B0numb, sp>AE> <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>AB0M53(<);d ivclassNa="meco"> = new Map("><);d>);d>);d>AEconsB0s7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>11SAB0striAE> <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>AB0S53(<);d ivclassNa="meco"> = new Set("><);d>);d>);d>AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Examp3 sp>53< {d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53proper sp>7<2:sp ansty="le--0:#D6DEEB;--1:#403F">52:sp><3 sp ansty="le--0:#FFCB8B;--1:#1111">11M3 sp>5<3B0stri353<, sp ansty="le--0:#C5E478;--1:#3B61">B0numb, sp>53<> sp ansty="le--0:#C792EA;--1:#8844">A> sp>5<3 sp ansty="le--0:#7FDBCA;--1:#096E">72n3 sp>5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0M3 sp>53( {d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"> = new Map();"><}d>}d>3}d> 44AEco61B<0map spans="tyle--0:#C792EA;--1:#88">44A0map>6E7<2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B4AE ><0Map spans="tyle--0:#C792EA;--1:#88">40Map><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>4461B0nu4<4AE> spans="tyle--0:#D6DEEB;--1:#40">3F54AE>><3() ;divclass="Name"><>()>>()>3()><;di vdivclass="Nameexpressive-">44AEco61B<0set spans="tyle--0:#C792EA;--1:#88">44A0set>6E7<2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B4AE ><0Set spans="tyle--0:#C792EA;--1:#88">40Set><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>4<4AE> spans="tyle--0:#D6DEEB;--1:#40">3F54AE>><3() ;divclass="Name"><>()>>()>3()>;di><;di vdivclass="Nameexpressive-">44AEco61B<0map spans="tyle--0:#7FDBCA;--1:#09">60map>4<4AE spans="tyle--0:#FFCB8B;--1:#11">1114AE ><1Map spans="tyle--0:#C792EA;--1:#88">41Map><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>4461B0nu44AE<> = spans="tyle--0:#7FDBCA;--1:#09">6E7> = ><2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B4AE ><0Map spans="tyle--0:#C792EA;--1:#88">40Map><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>4461B0nu4<4AE> spans="tyle--0:#D6DEEB;--1:#40">3F54AE>><3() ;divclass="Name"> = new Map<>()>>()>3()>;di><;di vdivclass="Nameexpressive-">44AEco61B<0map spans="tyle--0:#C792EA;--1:#88">44A0map>6E7<2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B4AE ><0Map spans="tyle--0:#D6DEEB;--1:#40">3F50Map><3() ;divclass="Name">3()>;di><;di vdivclass="Nameexpressive-">44AEc31111Exa3F<53 {divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F53prope53 >4<4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>6E7<2new spans="tyle--0:#D6DEEB;--1:#40">32new>61B<0Map spans="tyle--0:#D6DEEB;--1:#40">30Map>61B0st3F<53, spans="tyle--0:#C5E478;--1:#3B">61B0nu53, >3F5353 ><>() ;divclass="Nameec-">3>()>("><);>);>;di>
With the "type-annotation" style:
AEconsB0mAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>AB0MAB0striAE<, sp ansty="le--0:#C5E478;--1:#3B61">B0numb, sp>Asp ansty="le--0:#D6DEEB;--1:#403F">53(sp><);d ivclassNa="meco">("><);d>);d>);d>AEconsB0sAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>AB0SAB0striAsp ansty="le--0:#D6DEEB;--1:#403F">53(sp><);d ivclassNa="meco">("><);d>);d>);d> 44AEco61B<0map spans="tyle--0:#7FDBCA;--1:#09">60map>4<4AE spans="tyle--0:#FFCB8B;--1:#11">1114AE ><1Map spans="tyle--0:#C792EA;--1:#88">41Map><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>4461B0nu44AE<> = spans="tyle--0:#7FDBCA;--1:#09">6E7> = ><2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B4AE ><0Map spans="tyle--0:#D6DEEB;--1:#40">3F50Map><3() ;divclass="Name"> = new Ma">3()><;di vdivclass="Nameexpressive-">44AEco61B<0set spans="tyle--0:#7FDBCA;--1:#09">60set>4<4AE spans="tyle--0:#FFCB8B;--1:#11">1114AE ><1Set spans="tyle--0:#C792EA;--1:#88">41Set><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>44AE<> = spans="tyle--0:#7FDBCA;--1:#09">6E7> = ><2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B4AE ><0Set spans="tyle--0:#D6DEEB;--1:#40">3F50Set><3() ;divclass="Name"> = new Se">3()>;di><;di vdivclass="Nameexpressive-">44AEco61B<0map spans="tyle--0:#7FDBCA;--1:#09">60map>4<4AE spans="tyle--0:#FFCB8B;--1:#11">1114AE ><1Map spans="tyle--0:#C792EA;--1:#88">41Map><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>4461B0nu44AE<> = spans="tyle--0:#7FDBCA;--1:#09">6E7> = ><2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B4AE ><0Map spans="tyle--0:#C792EA;--1:#88">40Map><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>4461B0nu4<4AE> spans="tyle--0:#D6DEEB;--1:#40">3F54AE>><3() ;divclass="Name"> = new Map<>()>>()>3()>;di><;di vdivclass="Nameexpressive-">44AEco61B<0map spans="tyle--0:#C792EA;--1:#88">44A0map>6E7<2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B4AE ><0Map spans="tyle--0:#D6DEEB;--1:#40">3F50Map><3() ;divclass="Name">3()>;di>
Which side should specify the type arguments:
"constructor" (default): Type arguments should be on the constructor call.
"type-annotation": Type arguments should be on the type annotation.
If your codebase prefers to keep an inconsistent preference for one style over the other, you may not need this rule.
Some teams prefer to use whichever style feels more natural in each context.