💼🚫 This rule is enabled in the 🎨 stylistic
config. This rule is disabled in the disableTypeChecked
config.
💭 This rule requires type information.
There are two ways function members can be declared in interfaces and type aliases; MethodSignature
and PropertySignature
.
The MethodSignature
and the PropertySignature
forms seem equivalent, but only the PropertySignature
form can have
a readonly
modifier.
Because of this any MethodSignature
will be mutable unless wrapped in the Readonly
type.
It should be noted however that the PropertySignature
form does not support overloading.
/* eslint functional/prefer-property-signatures: "error" */
type Foo = {
bar(): string;
};
/* eslint functional/prefer-property-signatures: "error" */
type Foo = {
bar: () => string;
};
type Foo = {
readonly bar: () => string;
};
This rule accepts an options object of the following type:
type Options = {
ignoreIfReadonlyWrapped: boolean;
};
const defaults = {
ignoreIfReadonlyWrapped: false,
};
If set to true
, method signatures wrapped in the Readonly
type will not be flagged as violations.
/* eslint functional/prefer-property-signatures: ["error", { "ignoreIfReadonlyWrapped": true } ] */
type Foo = Readonly<{
bar(): string;
}>;