Skip to content

objectShorthand

Object property and method definitions can use shorthand syntax when the key matches the value identifier or when a function expression is assigned.

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

ES2015 introduced shorthand syntax for object literals, allowing more concise property and method definitions. When a property value is an identifier with the same name as the property key, or when a function expression is assigned to a property, shorthand syntax can be used.

AEconsB0naAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DAli1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">AEconsB0usAE = { name<: sp ansty="le--0:#D6DEEB;--1:#403F">53naAE< }sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><};d>AEconsB0valAE <= sp ansty="le--0:#F78C6C;--1:#AA09">82<42sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">AEconsB0settinAE = { value<: sp ansty="le--0:#D6DEEB;--1:#403F">53valAE, other<: sp ansty="le--0:#FF6A83;--1:#A248">48trAE< }sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><};d>
44AEco61B044A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DA1<111" spans="tyle--0:#D6DEEB;--1:#40">344AEco61B044AE <= { spans="tyle--0:#D6DEEB;--1:#40">3F53443<;di vdivclass="Nameexpressive-">44AEco61B0v44A09<8242 spans="tyle--0:#D6DEEB;--1:#40">344AEco61B0sett44AE <= { spans="tyle--0:#D6DEEB;--1:#40">3F53v44AE, oth4848443
AEconsB0confAE =< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0handlAE: functio11<()sp ansty="le--0:#C792EA;--1:#8844">AE< {d ivclassNa="meec-li">AE < sp ansty="le--0:#C792EA;--1:#8844">AEretur1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dresu1<1"sp ansty="le--0:#C792EA;--1:#8844">AAE< sp ansty="le--0:#C792EA;--1:#8844">AE<},d ivclassNa="meec-li">A5<3;d ivclassNa="meco"><};d>AEconsB0serviAE =< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0loAE: async functio11<()sp ansty="le--0:#C792EA;--1:#8844">AE< {d ivclassNa="meec-li">AE < sp ansty="le--0:#C792EA;--1:#8844">AEreturn awaiB0PromiAB0resol5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dda1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AAE< sp ansty="le--0:#C792EA;--1:#8844">AE<},d ivclassNa="meec-li">A5<3;d ivclassNa="meco"><};d>
44AEco61B0co44AE< = {divclass="Nameec-">de61B0han11<11() spans="tyle--0:#C792EA;--1:#88">4444AE< spans="tyle--0:#C792EA;--1:#88">44AEret1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dre1<111" spans="tyle--0:#C792EA;--1:#88">4<4AE ;divclass="Nameec-">44444<4AE} spans="tyle--0:#D6DEEB;--1:#40">3<,}><;di vdivclass="Nameexpressive-">44AEco61B0ser44AE< = {divclass="Nameec-">4444AEas61B011<11() spans="tyle--0:#C792EA;--1:#88">4444AE< spans="tyle--0:#C792EA;--1:#88">44AEreturn aw61B0Pro4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0res31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#D6DEEB;--1:#40">34<4AE ;divclass="Nameec-">44444<4AE} spans="tyle--0:#D6DEEB;--1:#40">3<,}>
AEconsB0iteratAE =< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0valuAE: function<* sp ansty="le--0:#D9F5DD;--1:#1111">11<()sp ansty="le--0:#C792EA;--1:#8844">AE< {d ivclassNa="meec-li">AE < sp ansty="le--0:#C792EA;--1:#8844">AEyiel8<21sp ansty="le--0:#C792EA;--1:#8844">AAE < sp ansty="le--0:#C792EA;--1:#8844">AEyiel8<22sp ansty="le--0:#C792EA;--1:#8844">AAE< sp ansty="le--0:#C792EA;--1:#8844">AE<},d ivclassNa="meec-li">A5<3;d ivclassNa="meco"><};d>
44AEco61B0iter44AE< = {divclass="Nameec-">444<4AE* spans="tyle--0:#82AAFF;--1:#3B">61B0va11<11() spans="tyle--0:#C792EA;--1:#88">4444AE< spans="tyle--0:#C792EA;--1:#88">44AEyi0<9821 spans="tyle--0:#C792EA;--1:#88">4<4AE ;divclass="Nameec-">44AE< spans="tyle--0:#C792EA;--1:#88">44AEyi0<9822 spans="tyle--0:#C792EA;--1:#88">4<4AE ;divclass="Nameec-">44444<4AE} spans="tyle--0:#D6DEEB;--1:#40">3<,}>

This rule is not configurable.

If your project targets environments that don’t support ES2015 shorthand syntax, this rule should be disabled.

Arrow functions used as property values that rely on lexical this, arguments, super, or new.target bindings are not flagged by this rule, as converting them to method shorthand would change their behavior.

Some codebases prefer explicit property assignments for consistency or clarity, particularly when mixing shorthand and longform syntax in the same object literal.