Skip to content

accessorPairTypes

Reports mismatched types between getter and setter accessor pairs.

✅ This rule is included in the ts logical and logicalStrict presets.

TypeScript allows defining different types for a getter return and its corresponding setter parameter. Defining drastically different types for a getter and setter can be confusing, as it means assigning a property to itself would not work.

This rule reports cases where a getter and setter have the same name but the getter’s return type is not assignable to the setter’s parameter type.

class Example {
get value(): string {
return this._value;
}
set value(newValue: number) {
this._value = String(newValue);
}
}
interface Config {
get value(): string;
set value(newValue: number);
}

This rule is not configurable.

If your project needs to model unusual relationships between data, such as older DOM types, this rule might not be for you. You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.