Reports getter functions that do not return values.
✅ This rule is included in the ts javascript presets.
The get syntax binds an object property to a function that will be called when that property is looked up.
A getter is expected to return a value; otherwise, accessing the property will return undefined, which is likely unintentional.
This rule reports when a getter does not explicitly return a value.
AEconsB0objeAE =< {d ivclassNa="meec-li">AE< sp ansty="le--0:#C792EA;--1:#8844">AEge sp>B0val11<()sp ansty="le--0:#C792EA;--1:#8844">AE()sp> {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#D6DEEB;--1:#403F">53conso sp>AB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Daccess1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp><3)sp ansty="le--0:#C792EA;--1:#8844">A3)sp> {d>AE< sp ansty="le--0:#C792EA;--1:#8844">AE sp><},d ivclassNa="meec-li">A5},d><3;d ivclassNa="meco"><};d>};d>3;d>AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Examp3 sp>53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEg sp>5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0val3 sp>11<()sp ansty="le--0:#D6DEEB;--1:#403F">53()sp> {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72th sp>AB0compu53( {d><);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>);d><3}d ivclassNa="meec-li">53}d><3}d ivclassNa="meco"><}d>}d>3}d>AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Examp3 sp>53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEg sp>5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0val3 sp>11<()sp ansty="le--0:#D6DEEB;--1:#403F">53()sp> {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu sp>5 {d><3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>3;d><3}d ivclassNa="meec-li">53}d><3}d ivclassNa="meco"><}d>}d>3}d> 44AEco61B0ob44AE< = {divclass="Nameec-">4444AE61B0v11<11() spans="tyle--0:#C792EA;--1:#88">4411()> = >44AE< spans="tyle--0:#C792EA;--1:#88">44AEret >6E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72_v4AE.>4<4AE ;divclass="Nameec-">44444AE>4<4AE} spans="tyle--0:#D6DEEB;--1:#40">34AE}><,}>,}><;di vdivclass="Nameexpressive-">44AEc31111Exa3F<53 {divclass="Nameec-">de44A361B0v11<11() spans="tyle--0:#D6DEEB;--1:#40">3F11()>53 ><53 {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44AEre >36E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72_v4AE.>353 >3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }>;di><}di vdivclass="Nameexpressive-">44AEc31111Exa3F<53 {divclass="Nameec-">de44A361B0v11<11() spans="tyle--0:#D6DEEB;--1:#40">3F11()>53 ><53 {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44 >3F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E7253 (>4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72condi4AE.>3F553 ><3) {divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AEre >36E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E724AE.>33) >3F53< spans="tyle--0:#D6DEEB;--1:#40">3 >dent< spans="tyle--0:#C792EA;--1:#88">44AEre >36E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72defaultV4AE.>33F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }>}di>
This rule is not configurable.
TypeScript’s compiler already enforces that getters with an explicit return type must return a value.
If all getters in your codebase use explicit return types, you might not need this rule.
However, this rule also catches implicit undefined returns in getters that lack return type annotations.