oxc-project/oxc · warning · OxcDiagnostic

Use `void` only as a return type.

Error message

Use `void` only as a return type.

What it means

Base message of no-invalid-void-type: `void` means 'this function's return value is ignored', so using it in any position other than a return type is flagged. This variant (no_invalid_void_type.rs:30-36) is the one emitted when the config permits no other allowances, such as generic type arguments.

Source

Thrown at crates/oxc_linter/src/rules/typescript/no_invalid_void_type.rs:29

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

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

fn invalid_void_for_generic_diagnostic(span: Span, generic: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Do not use `void` as a type argument for `{generic}`."))
        .with_help(
            "Replace this `void` type with an allowed type, or keep `void` only in a valid return position.",
        )
        .with_label(span)
}

fn invalid_void_not_return_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use `void` only as a return type.")
        .with_help(
            "Replace this `void` type with an allowed type, or keep `void` only in a valid return position.",
        )
        .with_label(span)
}

fn invalid_void_not_return_or_generic_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use `void` only as a return type or generic type argument.")
        .with_help(
            "Replace this `void` type with an allowed type, or keep `void` only in a valid return position.",
        )
        .with_label(span)
}

fn invalid_void_not_return_or_this_param_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use `void` only as a return type or as the type of a `this` parameter.")
        .with_help(
            "Replace this `void` type with an allowed type, or keep `void` only in a valid return position.",

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace the annotation with `undefined`
  2. Restructure so the value is a function return (where `void` is legal)
  3. Re-enable the allowances you need in the rule config

Example fix

// before
let result: void;

// after
let result: undefined;
Defensive patterns

Strategy: validation

Validate before calling

npx oxlint --deny-warnings .

Prevention

When it happens

Trigger: `let x: void`, a parameter annotated `void`, `void` as an object property type, with allowInGenericTypeArguments disabled so no generic slot is permitted either.

Common situations: Developers using `void` where they mean `undefined`; config tightened to ban generics, making previously tolerated usages fail.

Related errors


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