Skip to content

arrayFlatMapMethods

Reports using .map().flat() when .flatMap() can be used.

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

Array.prototype.flatMap() combines mapping and flattening in a single step. Using .map().flat() creates an intermediate array that is immediately discarded, which is less efficient. This rule reports when .map().flat() can be replaced with .flatMap().

The rule only applies when .flat() is called with no arguments or with a depth of 1, since .flatMap() always flattens to a depth of one level.

AEdeclare consB0arr7<2:sp ansty="le--0:#C792EA;--1:#8844">AB0numb53[<];d ivclassNa="meec-li">53arrAB0m5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val1<1)sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<=>sp ansty="le--0:#D6DEEB;--1:#403F">53 [value, valusp>A5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#D6DEEB;--1:#403F">53<])sp ansty="le--0:#C792EA;--1:#8844">AB0fl53(<);d ivclassNa="meco"><);d>AEdeclare consB0strin7<2:sp ansty="le--0:#C792EA;--1:#8844">AB0stri53[<];d ivclassNa="meec-li">53strinAB0m5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val1<1)sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<=>sp ansty="le--0:#D6DEEB;--1:#403F">53 valsp>AB0spl5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">41<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<))sp ansty="le--0:#C792EA;--1:#8844">AB0fl53(<);d ivclassNa="meco"><);d>AEdeclare consB0arr7<2:sp ansty="le--0:#C792EA;--1:#8844">AB0numb53[<];d ivclassNa="meec-li">53arrAB0m5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val1<1)sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<=>sp ansty="le--0:#D6DEEB;--1:#403F">53 [valuesp><])sp ansty="le--0:#C792EA;--1:#8844">AB0fl5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEdeclare co61B0a64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu3F5<3[] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0fla31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v1<111) spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3F53 [value, va>4<4AE* spans="tyle--0:#D6DEEB;--1:#40">30<9822 spans="tyle--0:#D6DEEB;--1:#40">3F5<3]) ;divclass="Name"><2])><;di vdivclass="Nameexpressive-">44AEdeclare co61B0str64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0st3F5<3[] ;divclass="Nameec-">3F53str4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0fla31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v1<111) spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3F53 v>4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0s31<111" spans="tyle--0:#ECC48D;--1:#98">41<111" spans="tyle--0:#D6DEEB;--1:#40">3F5<3)) ;divclass="Name"><"))><;di vdivclass="Nameexpressive-">44AEdeclare co61B0a64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu3F5<3[] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0map spans="tyle--0:#D6DEEB;--1:#40">31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v1<111) spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3F53 [[valu>4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B030<9822 spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><(2)><;di vdivclass="Nameexpressive-">44AEdeclare co61B0a64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu3F5<3[] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B03F5<3() ;divclass="Name">

This rule is not configurable.

If you prefer the explicit two-step approach of .map().flat() for readability, or if your codebase has a large number of existing uses that would be difficult to refactor, you may disable this rule.