@typescript-eslint/no-meaningless-void-operator

Disallow void in front of an expression that has no value to discard

fixableneeds types

Also called typescript-eslint/no-meaningless-void-operator, typescript/no-meaningless-void-operator

void in front of a call says "this returns something, and I'm ignoring it on purpose". If the call returns nothing, or the thing after void isn't a call at all, there's nothing to ignore, and the reader looks for a return value that isn't there.

void 0, void in front of a promise and void in front of an assignment are allowed.

--fix removes the void. In front of something that isn't a call, it only does that when the void expression is a whole statement.

Configure#

Off by default. This rule needs types, so turning it on makes bun lint type check your code first.

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

Every option, set to its default:

bunfig.toml
[lint.rules]
"@typescript-eslint/no-meaningless-void-operator" = ["error", {
  checkNever = false,
}]

Examples#

example.ts2 problems
function log(message: string): void {
  console.log(message);
}

void log("saved");

const count = 3;
void count;
example.tsNo problems
function log(message: string): void {
  console.log(message);
}

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

log("saved");
void save();

Options#

OptionDefaultWhat it does
checkNeverfalseAlso report void in front of a call that returns never. --fix leaves these alone.

Reported with checkNever: true:

example.tswith { "checkNever": true }1 problem
function fail(message: string): never {
  throw new Error(message);
}

void fail("no config");