Skip to content

getterReturns

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">AEgeB0val11<()sp ansty="le--0:#C792EA;--1:#8844">AE< {d ivclassNa="meec-li">nt < sp ansty="le--0:#D6DEEB;--1:#403F">53consoAB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Daccess1<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>AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Examp53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEg5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0val11<()sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#7FDBCA;--1:#096E">72thAB0compu53(<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Examp53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEg5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0val11<()sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu5<3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
44AEco61B0ob44AE< = {divclass="Nameec-">4444AE61B0v11<11() spans="tyle--0:#C792EA;--1:#88">4444AE< spans="tyle--0:#C792EA;--1:#88">44AEret6E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72_v4<4AE ;divclass="Nameec-">44444<4AE} spans="tyle--0:#D6DEEB;--1:#40">3<,}><;di vdivclass="Nameexpressive-">44AEc31111Exa3F<53 {divclass="Nameec-">de44A361B0v11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44AEre36E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72_v33F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }><}di vdivclass="Nameexpressive-">44AEc31111Exa3F<53 {divclass="Nameec-">de44A361B0v11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72condi3F5<3) {divclass="Nameec-">dent < spans="tyle--0:#C792EA;--1:#88">44AEre36E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E7233F53< spans="tyle--0:#D6DEEB;--1:#40">3dent< spans="tyle--0:#C792EA;--1:#88">44AEre36E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72defaultV33F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }>

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.