oxc-project/oxc · warning · OxcDiagnostic

Do not use `void` as a type argument for `{generic}`.

Error message

Do not use `void` as a type argument for `{generic}`.

What it means

Message from no-invalid-void-type that interpolates the generic name: using `void` as a type argument (for example `Array<void>`) is only allowed for generics listed in allowInGenericTypeArguments (a boolean or a list such as Promise). When the generic in use is not permitted, this diagnostic fires with its name filled into the warn at no_invalid_void_type.rs:21-26.

Source

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

    ast::{
        ClassElement, Declaration, ExportDefaultDeclarationKind, Function, FunctionType,
        MethodDefinition, ModuleDeclaration, Statement, TSType, TSUnionType,
    },
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
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.",

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Use `undefined` as the type argument (`Array<undefined>`)
  2. Add the generic name to allowInGenericTypeArguments (for example "Promise")
  3. Set allowInGenericTypeArguments: true to permit all generics

Example fix

// before
const steps: Array<void> = [];

// after
const steps: Array<undefined> = [];
Defensive patterns

Strategy: validation

Validate before calling

{
  "rules": {
    "typescript/no-invalid-void-type": ["error", { "allowInGenericTypeArguments": ["Promise"] }]
  }
}

Prevention

When it happens

Trigger: `let x: Array<void>`, `Foo<void>` where Foo is not in allowInGenericTypeArguments; configuring the option as an explicit list that omits the generic you actually use.

Common situations: Teams restricting `void` to return positions by narrowing the allow list; debates over Promise<void> versus Promise<undefined> in callback-heavy APIs.

Related errors


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