oxc-project/oxc · warning · OxcDiagnostic

Remove `void` from this union type constituent.

Error message

Remove `void` from this union type constituent.

What it means

The union-constituent message of no-invalid-void-type: `void` inside a union type (such as `string | void`) is nearly always a mistake because the union cannot express 'maybe undefined' cleanly and assignment behavior surprises readers. The rule asks you to remove it (no_invalid_void_type.rs:64-68).

Source

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

    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>);

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(untagged)]
pub enum AllowInGenericTypeArguments {
    Boolean(bool),
    AllowList(Vec<String>),
}

impl Default for AllowInGenericTypeArguments {
    fn default() -> Self {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace `void` in the union with `undefined`
  2. Drop `void` from the union if it was accidental
  3. Keep `void` alone as a bare return type where intended

Example fix

// before
type Result = string | void;

// after
type Result = string | undefined;
Defensive patterns

Strategy: validation

Validate before calling

npx oxlint --deny-warnings .

Prevention

When it happens

Trigger: `type T = string | void;`, `function f(): number | void`, `Promise<void | null>` in positions the config checks.

Common situations: Developers mixing up `void` and `undefined` in optional callback chains; refactors that merged return types into unions.

Related errors


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