voidOperator
Reports using the void operator.
✅ This rule is included in the ts stylistic
preset.
The void
operator evaluates an expression and returns undefined
, regardless of the expression’s value.
While this was historically used to safely obtain undefined
, modern JavaScript has undefined
as a proper value, making the void
operator unnecessary and potentially confusing.
void 0
is specifically used in minified code to lower total character size, but that is not necessary in source code.
Using undefined
directly is clearer and more explicit.
Examples
Section titled “Examples”const value = void 0;
function process() { void doSomething();}
const callback = () => void action();
const value = undefined;
function process() { doSomething();}
const callback = () => { action(); return undefined;};
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you have a specific code style that requires the use of void
operator, you might want to disable this rule.
However, in most modern codebases, using undefined
directly is preferred for clarity.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noVoid
- ESLint:
no-void
- Oxlint:
eslint/no-void
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.