Skip to content

misleadingVoidExpressions

Require expressions of type void to appear in statement position.

✅ This rule is included in the ts logical presets.

The void type in TypeScript refers to a function return that is meant to be ignored. Using a void-typed value—such as assigning the result of a called function to a variable or returning it from another function—is often a programmer error. Even when used correctly, void expressions in value positions can be misleading for other developers.

This rule reports void expressions that are used in misleading locations such as being assigned to a variable, provided as a function argument, or returned from a function.

declare function log(message: string): void;
const result = log("hello");
declare function log(message: string): void;
[1, 2, 3].forEach((n) => log(String(n)));
declare function log(message: string): void;
function run() {
return log("done");
}

This rule is not configurable.

If you frequently use concise arrow function shorthands that return void, or if your codebase intentionally uses void expressions as values in certain patterns, you may not need this rule. The return type of a function can be inspected by going to its definition or hovering over it in an IDE, so some teams prefer relying on IDE hints rather than lint rules for this purpose.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.