Skip to main content

prefer-function-type

Use function types instead of interfaces with call signatures.

Rule Details

This rule suggests using a function type instead of an interface or object type literal with a single call signature.

Examples of code for this rule:

interface Foo {
(): string;
}
function foo(bar: { (): number }): number {
return bar();
}
interface Foo extends Function {
(): void;
}
interface MixinMethod {
// returns the function itself, not the `this` argument.
(arg: string): this;
}

Options

// .eslintrc.json
{
"rules": {
"@typescript-eslint/prefer-function-type": "warn"
}
}

This rule is not configurable.

When Not To Use It

If you specifically want to use an interface or type literal with a single call signature for stylistic reasons, you can disable this rule.

Further Reading

Attributes

  • Configs:
    • ✅ Recommended
    • 🔒 Strict
  • 🔧 Fixable
  • 💭 Requires type information