Skip to content

fix(lint): infer void return type for block-bodied arrow functions#825

Open
crowlbot wants to merge 2 commits into
mainfrom
fix/arrow-void-return-inference
Open

fix(lint): infer void return type for block-bodied arrow functions#825
crowlbot wants to merge 2 commits into
mainfrom
fix/arrow-void-return-inference

Conversation

@crowlbot

Copy link
Copy Markdown
Contributor

Problem

deno doc --lint raised a spurious missing-return-type diagnostic for an exported const initialized with a block-bodied arrow function, while the equivalent function expression was accepted:

export const a1 = () => {};        // ❌ missing-return-type (before)
export const b1 = function () {};  // ✅ ok

Both forms implicitly return void (or Promise<void> when async), so the lint should treat them identically. The arrow/function-expression discrepancy was reported in #823.

Fix

function_to_function_def already inferred void/Promise<void> for function expressions whose body has no value-returning return. This extracts that logic into a shared inferred_void_return_type helper and applies it to block-bodied arrow functions as well.

Behavior after the change is consistent across both forms:

source inferred return
() => {} / function () {} void
async () => {} / async function () {} Promise<void>
() => { return 1; } / function () { return 1; } none → missing-return-type (unchanged)
() => 1 (expression body returning a value) none → missing-return-type (unchanged)

Expression-bodied arrows (() => 1) and bodies containing a value-returning return are deliberately left alone — inferring those would require type-checking the body.

Test

Adds tests/specs/function_const_return_type_inference.txt, covering arrow vs. function-expression parity for void inference, async inference, variable-annotation satisfaction, and the value-returning cases that still require an explicit annotation.

Fixes #823

An exported arrow function with a block body and no value-returning
return statement implicitly returns void (or Promise<void> when async),
exactly like a function expression. Previously only function
expressions had this return type inferred, so a const initialized with
an arrow like `() => {}` raised a spurious missing-return-type lint
diagnostic while the equivalent `function () {}` did not.

Share the inference via a helper and apply it to arrow bodies.
@crowlbot crowlbot requested a review from crowlKats June 23, 2026 11:24
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deno doc --lint requires extra return type for arrow functions but not function expressions

2 participants