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
class Example
Example
{
get
Example.value: string
value
(): string {
return this.
any
_value
;
}
set
Example.value: number
value
(
newValue: number
newValue
: number) {
this.
any
_value
=
var String: StringConstructor
(value?: any) => string

Allows manipulation and formatting of text strings and determination and location of substrings within strings.

String
(
newValue: number
newValue
);
}
}
interface
interface Config
Config
{
get
Config.value: string
value
(): string;
set
Config.value: number
value
(
newValue: number
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 ❤️‍🔥 around the world by the Flint team and contributors.