Skip to content

accessorPairGroups

Reports getter and setter accessors for the same property that are not adjacent.

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

Grouping getters and setters together improves code readability. When a property has both a getter and a setter, defining them adjacent to each other makes it easier to understand how the property is accessed and modified.

class
class Example
Example
{
get
Example.value: number
value
() {
return this._value;
Error ts(2551) ― Property '_value' does not exist on type 'Example'. Did you mean 'value'?
}
Example.otherMethod(): void
otherMethod
() {}
set
Example.value: number
value
(
newValue: number
newValue
: number) {
this._value =
newValue: number
newValue
;
Error ts(2551) ― Property '_value' does not exist on type 'Example'. Did you mean 'value'?
}
}
const
const object: {
value: number;
other: number;
}
object
= {
get
value: number
value
() {
return this._value;
Error ts(2551) ― Property '_value' does not exist on type '{ value: number; other: number; }'. Did you mean 'value'?
},
other: number
other
: 42,
set
value: number
value
(
newValue: number
newValue
: number) {
this._value =
newValue: number
newValue
;
Error ts(2551) ― Property '_value' does not exist on type '{ value: number; other: number; }'. Did you mean 'value'?
},
};

This rule is not configurable.

If you prefer a different organization style for class members, such as grouping by visibility or functionality, you might choose to disable this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.