Content-Length: 297184 | pFad | http://github.com/typescript-eslint/typescript-eslint/issues/11354

CF Enhancement: [no-unsafe-return] Option to check Promise<any> in non-async function · Issue #11354 · typescript-eslint/typescript-eslint · GitHub
Skip to content

Enhancement: [no-unsafe-return] Option to check Promise<any> in non-async function #11354

Open
@sohcah

Description

@sohcah

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-unsafe-return/

Description

I can see from previous discussions in #8674 that there was a decision not to ban returning Promise<any> in returns from non-async promises.

It would be quite nice to allow banning this type since there are situations, such as below, where code can be written with chained promises where anys can be allowed into code without any errors.

declare function hello(getName: () => Promise<string>): Promise<void>;

// Avoids error currently
await hello(() => fetch("/name/get").then((i) => i.json()));

// Gives error
await hello(async () => fetch("/name/get").then((i) => i.json()));

// Gives error
await hello(async () => {
  const response = await fetch("/name/get");
  return await response.json();
});

Fail

declare function hello(getName: () => Promise<string>): Promise<void>;

await hello(() => fetch("/name/get").then((i) => i.json()));

Pass

declare function hello(getName: () => Promise<string>): Promise<void>;

await hello(() => fetch("/name/get").then((i) => i.json() as Promise<string>));

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: http://github.com/typescript-eslint/typescript-eslint/issues/11354

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy