getterReturns
Reports getter functions that do not return values.
✅ This rule is included in the ts untyped 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.
Examples
Section titled “Examples”const object = { get value() { console.log("accessed"); },};class Example { get value() { this.compute(); }}class Example { get value() { return; }}const object = { get value() { return this._value; },};class Example { get value() { return this._value; }}class Example { get value() { if (this.condition) { return this.data; } return this.defaultValue; }}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useGetterReturn - Deno:
getter-return - ESLint:
getter-return - Oxlint:
eslint/getter-return
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.