Closed
Description
Search Terms
missing await error refactoring
Suggestion
Missing an await
can cause some confusion especially for people who haven't used async/await before. A helpful error message when you have a Promise<T> instead of T that suggests maybe an await is missing might help address this. There are at least a few common cases this comes up:
- Using operators, and T is a primitive type. If T were say an object type, it seems more likely something else is wrong with the code to me.
- Passing to a function, and T is a valid parameter at that position.
- for-of and T is some array type
- The target of a member expression and T has the member (or maybe the property name is not in Promise).
A quick fix could also be considered. When in an async function and an error such as above appears, a quick fix that adds an await before the source of the promise within that function.
Use Cases
It helps people realize when they need an await.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.