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.

const object = {
get value() {
console.log("accessed");
},
};
class Example {
get value() {
this.compute();
}
}
class Example {
get value() {
return;
}
}

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.