oxc-project/oxc · warning · OxcDiagnostic

Use `void` only as a return type, generic type argument, or

Error message

Use `void` only as a return type, generic type argument, or the type of a `this` parameter.

What it means

The most permissive single-position variant of the no-invalid-void-type message (no_invalid_void_type.rs:54-60): it lists return types, generic type arguments, and `this` parameter types as the allowed positions, and fires for `void` used anywhere else under a config that permits all three.

Source

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

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.",
        )
        .with_label(span)
}

fn invalid_void_not_return_or_this_param_or_generic_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(
        "Use `void` only as a return type, generic type argument, or 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.",
    )
    .with_label(span)
}

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

#[derive(Debug, Default, Clone, Deserialize)]
pub struct NoInvalidVoidType(Box<NoInvalidVoidTypeConfig>);

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace the offending `void` with `undefined`
  2. Restructure the code so `void` lands in a return type
  3. Align the annotation with one of the allowed positions or relax the rule config deliberately

Example fix

// before
interface State {
  loaded: void;
}

// after
interface State {
  loaded: undefined;
}
Defensive patterns

Strategy: validation

Validate before calling

npx oxlint --deny-warnings .

Prevention

When it happens

Trigger: `let v: void`, `obj.prop: void`, `(x: void) => x` - any non-return, non-generic, non-this usage under the fully permissive configuration.

Common situations: Large codebases where different teams use different allowances; central lint config permissive on generics and this-params while individual annotations still misuse `void`.

Related errors


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