Open
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
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 any
s 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