oxc-project/oxc · error

Enforce using function types instead of interfaces with call

Error message

Enforce using function types instead of interfaces with call signatures.

What it means

Lint diagnostic from typescript/prefer-function-type: an interface containing only a call signature was found. A type alias with a function type is the idiomatic, more concise equivalent and the rule's fixer can usually rewrite it automatically.

Source

Thrown at crates/oxc_linter/src/rules/typescript/prefer_function_type.rs:18

use oxc_ast::{
    AstKind,
    ast::{ExportDefaultDeclarationKind, TSInterfaceDeclaration, TSSignature, TSType, TSTypeName},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    fixer::Fix,
    rule::Rule,
};

fn prefer_function_type_diagnostic(suggestion: &str, span: Span) -> OxcDiagnostic {
    // FIXME: use imperative message phrasing
    OxcDiagnostic::warn("Enforce using function types instead of interfaces with call signatures.")
        .with_help(format!("The function type form `{suggestion}` is generally preferred when possible for being more succinct."))
        .with_label(span)
}

const CONVERT_TO_FUNCTION_TYPE: &str = "Convert to function type";

#[derive(Debug, Default, Clone)]
pub struct PreferFunctionType;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Enforce using function types instead of interfaces with call signatures.
    ///
    /// ### Why is this bad?
    ///
    /// TypeScript allows for two common ways to declare a type for a function:
    /// - Function type: `() => string`

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace the interface with a type alias, e.g. interface Foo { (x: number): string } -> type Foo = (x: number) => string
  2. Apply the rule's autofix
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/prefer_function_type.rs:18 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/80d4be9c79d3fd0a. Report an issue: GitHub.