# @typescript-eslint/no-invalid-void-type

> Disallow `void` outside of return types and generic type arguments

`void` says that the caller should ignore what a function returns. Anywhere else it's confusing, because a variable or a parameter of type `void` can only hold `undefined`. Write `undefined` there, or make the parameter optional.

`void` is fine as a return type and as a type argument, such as `Promise<void>`. A union is fine if every member is `void`, `never` or a generic type with `void` as an argument.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-invalid-void-type" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-invalid-void-type" = ["error", {
  allowInGenericTypeArguments = true,
  allowAsThisParameter = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```ts
let result: void;

function log(message: string | void) {}

type Listener = (event: void) => void;
```

Not reported:

{/* good */}
```ts
let result: undefined;

function log(message?: string): void {}

async function save(): Promise<void> {}

type MaybeAsync = void | Promise<void>;
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowInGenericTypeArguments` | `true` | `false` reports `void` as a type argument. A list of names allows it only for those types. |
| `allowAsThisParameter` | `false` | Allow `this: void`, which says that a function doesn't use `this`. |

{/* bad {"options": [{"allowInGenericTypeArguments": false}]} */}
```ts
async function save(): Promise<void> {}
```

With a list, `void` is allowed as an argument of the types in it:

{/* good {"options": [{"allowInGenericTypeArguments": ["Promise"]}]} */}
```ts
async function save(): Promise<void> {}
```

{/* bad {"options": [{"allowInGenericTypeArguments": ["Promise"]}]} */}
```ts
const results: Array<void> = [];
```

`this: void` is reported unless you turn on `allowAsThisParameter`:

{/* bad */}
```ts
function now(this: void) {
  return Date.now();
}
```

{/* good {"options": [{"allowAsThisParameter": true}]} */}
```ts
function now(this: void) {
  return Date.now();
}
```
