Skip to content
← Back to rules

typescript/no-invalid-void-type Restriction

What it does

Disallow void type usage outside return types and configured generic contexts.

Why is this bad?

In TypeScript, void is primarily meaningful in return positions. Using void in other type locations (parameters, properties, aliases, and most unions) is usually confusing and often indicates a mistaken type design.

Examples

Examples of incorrect code for this rule:

ts
function takeVoid(arg: void) {}
type Alias = void;
type Union = string | void;

Examples of correct code for this rule:

ts
function f(): void {}
type P = Promise<void>;
type U = void | never;

Configuration

This rule accepts a configuration object with the following properties:

allowAsThisParameter

type: boolean

default: false

Whether a this parameter of a function may be void.

allowInGenericTypeArguments

type: array | boolean

allowInGenericTypeArguments[n]

type: string

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "typescript/no-invalid-void-type": "error"
  }
}
bash
oxlint --deny typescript/no-invalid-void-type

References