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
- Replace the annotation with `undefined`
- Restructure so the value is a function return (where `void` is legal)
- 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
- Teach the distinction: `void` = ignored return, `undefined` = the value undefined
- Annotate variables and properties as `undefined | T`, never `void | T`
- Add the rule to the editor plugin so mistakes surface while typing
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
- Use `void` only as a return type or generic type argument.
- Use `void` only as a return type, generic type argument, or
- The generic type arguments should be specified as part of th
- The generic type arguments should be specified as part of th
- Do not use `void` as a type argument for `{generic}`.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/8bc692725a583d59.
Report an issue: GitHub.