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
- Use `undefined` as the type argument (`Array<undefined>`)
- Add the generic name to allowInGenericTypeArguments (for example "Promise")
- 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
- Use `undefined` whenever a slot means 'the undefined value' and reserve `void` for ignored returns
- Decide the team's Promise<void> policy once and encode it in allowInGenericTypeArguments
- Grep for `Array<void>` and `Map<..., void>` when adopting the rule
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
- The generic type arguments should be specified as part of th
- The generic type arguments should be specified as part of th
- Use `void` only as a return type.
- Use `void` only as a return type or generic type argument.
- Use `void` only as a return type or as the type of a `this`
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/1781f32da7bedb8a.
Report an issue: GitHub.