Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I havesearched for related issues and found none that match my proposal.
- I have searched thecurrent rule list and found no rules that match my proposal.
- I haveread the FAQ and my problem is not listed.
My proposal is suitable for this project
- My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
- My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Description
We have a number of public APIs in our project that return things likestring | Promise<string>
. In fact, we have so many of these that we have a helper type calledMaybePromise
. I believe it would be better if these functions always returned aPromise
. It would make a nicer API for callers because they would only have to worry about handling rejected promise errors and would not have to worry about errors that are thrown as well
I probably wouldn't want to apply this check to our whole project as internally we can have errors propagate in many functions, but I'd love to apply it to our public type definition file (.d.ts
).
Fail Cases
exportinterfaceEmulator{platform(details:{config:any;prerender:PrerenderOption}):App.Platform|Promise<App.Platform>;}
Pass Cases
exportinterfaceEmulator{platform(details:{config:any;prerender:PrerenderOption}):Promise<App.Platform>;}
Additional Info
promise-function-async
has a somewhat similar goal, but doesn't work for me because it ignores methods with explicit return types, which is one of the things I'd like to detect and disallow. It also has a ton of false positives on my existing codebase where it's almost always fine for me to just propagate errors upwards