Skip to content

misleadingVoidExpressions

Require expressions of type void to appear in statement position.

✅ This rule is included in the ts logical and logicalStrict 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
function log(message: string): void
log
(
message: string
message
: string): void;
const
const result: void
result
=
function log(message: string): void
log
("hello");
declare function
function log(message: string): void
log
(
message: string
message
: string): void;
[1, 2, 3].
Array<number>.forEach(callbackfn: (value: number, index: number, array: number[]) => void, thisArg?: any): void

Performs the specified action for each element in an array.

@paramcallbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

forEach
((
n: number
n
) =>
function log(message: string): void
log
(
var String: StringConstructor
(value?: any) => string

Allows manipulation and formatting of text strings and determination and location of substrings within strings.

String
(
n: number
n
)));
declare function
function log(message: string): void
log
(
message: string
message
: string): void;
function
function run(): void
run
() {
return
function log(message: string): void
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 ❤️‍🔥 around the world by the Flint team and contributors.