Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async function needs Promise<T> return type quick fix #36266

Closed
JacksonKearl opened this issue Jan 17, 2020 · 6 comments · Fixed by #36654
Closed

async function needs Promise<T> return type quick fix #36266

JacksonKearl opened this issue Jan 17, 2020 · 6 comments · Fixed by #36654
Assignees
Labels
Domain: Error Messages The issue relates to error messaging Domain: Quick Fixes Editor-provided fixes, often called code actions. Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this

Comments

@JacksonKearl
Copy link

JacksonKearl commented Jan 17, 2020

Search Terms

  • return type quick fix
  • async function quick fix
  • global promise type

Suggestion

It would be nice if TypeScript contributed a quick fix to resolve The return type of an async or global function must be the global Promise<T> type errors. The fix would simply wrap the existing return type into a Promise.

Checklist

My suggestion meets these guidelines:

  • [x ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ x] This wouldn't change the runtime behavior of existing JavaScript code
  • [ x] This could be implemented without emitting different JS based on the types of the expressions
  • [x ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [x ] This feature would agree with the rest of TypeScript's Design Goals.
@DanielRosenwasser
Copy link
Member

Could you provide an example of a before and after of the code fix? It's not clear what fix you're expecting.

@JacksonKearl
Copy link
Author

Before:

async doThing(): boolean { // Err: The return type of an async function must be the global Promise<T> type

}

After:

async doThing(): Promise<boolean> {

}

@Kingwl
Copy link
Contributor

Kingwl commented Jan 19, 2020

Related: #35300

@DanielRosenwasser DanielRosenwasser added Domain: Error Messages The issue relates to error messaging Domain: Quick Fixes Editor-provided fixes, often called code actions. Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this labels Jan 21, 2020
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jan 21, 2020

We should create a new specialized diagnostic for when the given type isn't assignable to PromiseLike<any> to add Did you mean to write 'Promise<{0}>'?

Then provide a quick fix to write Promise<{0}>.

@DanielRosenwasser
Copy link
Member

Looks like this didn't make it into 3.9. Will have to review with @mjbvz and @RyanCavanaugh whether it goes into 3.9.3 or 4.0

@JacksonKearl
Copy link
Author

!!!

hell yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Error Messages The issue relates to error messaging Domain: Quick Fixes Editor-provided fixes, often called code actions. Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants