strict-void-return
Added in v0.6.0Configuration
Rule Details
Disallow passing a value-returning function in a position accepting a void
function. TypeScript permits a function returning a value to be used where a
void-returning function is expected — callbacks can return any value and it
is silently discarded — but it hides several common mistakes: forgotten
awaits on promise-returning callbacks, generators or async functions misused
as fire-and-forget event handlers, and accidental dead values from arrow
shorthands. This rule reports any value-returning function used in a context
that expects a function whose return type is void. It checks function
arguments, JSX attribute values, array elements, assignments, variable
initializers, object properties, class members (against extended base classes
and implemented interfaces), and return statements.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
allowReturnAny
Type: boolean — Default: false
When false (default), a function returning any is treated the same as any
other non-void return — for example, fn(() => JSON.parse('{}')) is reported.
When true, functions returning any are accepted in void positions. Useful
for codebases where untyped values flow through callbacks intentionally.
Examples of correct code with { "allowReturnAny": true }: