oxc-project/oxc · error · OxcDiagnostic

The `Function` type accepts any function-like value.

Error message

The `Function` type accepts any function-like value.

What it means

Raised by typescript/no-unsafe-function-type when the global `Function` type or the new Function() constructor is used. `Function` accepts any callable and defeats type checking of parameters and return values.

Source

Thrown at crates/oxc_linter/src/rules/typescript/no_unsafe_function_type.rs:13

use oxc_ast::{
    AstKind,
    ast::{IdentifierReference, TSTypeName},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::IsGlobalReference;
use oxc_span::Span;

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

fn no_unsafe_function_type_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("The `Function` type accepts any function-like value.")
        .with_help("Prefer explicitly defining any function parameters and return type.")
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow using the unsafe built-in Function type.
    ///
    /// ### Why is this bad?
    ///
    /// TypeScript's built-in Function type allows being called with any number of arguments and returns type any. Function also allows classes or plain objects that happen to possess all properties of the Function class. It's generally better to specify function parameters and return types with the function type syntax.
    ///
    /// ### Examples
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Define an explicit function type: (arg: string) => void.
  2. Use typed callback signatures instead of `Function`.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/no_unsafe_function_type.rs:13 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/e7f68716a711637c. Report an issue: GitHub.