Skip to content

Feature request: Disallow returning a void-returning function result #2425

@d-luk

Description

@d-luk

I've seen the following pattern in code several times now, and it leads to some confusion:

function doSomething(): void {
    // Returns nothing
}

const result = await myPromise.then(() => {
    return doSomething();
});

The bottom statement suggests that a value is being returned from doSomething(), while in reality its type is void.

It would be great to have a rule that enforces removing this misleading return keyword:

const result = await myPromise.then(() => {
    doSomething();
});

This code style removes the suggestion that result will be anything other than void / undefined.

I think this rule is a good fit for @typescript-eslint/eslint-plugin because it must know about the return type of the called function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy