accessorPairTypes
Reports mismatched types between getter and setter accessor pairs.
✅ This rule is included in the ts logical 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.
Examples
Section titled “Examples”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);}class Example { get value(): string { return this._value; } set value(newValue: string) { this._value = newValue; }}class Example { get value(): string { return this._value; } set value(newValue: string | number) { this._value = String(newValue); }}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”- MDN: Property accessors
- MDN: getter
- MDN: setter
- TypeScript 5.1: Unrelated Types for Getters and Setters