TypeScript Team | 0cf0fd0 | 2018-02-14 13:56:39 +0100 | [diff] [blame] | 1 | <!-- FIXME(alexeagle): generate the docs from the sources --> |
| 2 | |
| 3 | ## All promises in async functions must be used |
| 4 | |
| 5 | When using `async` / `await`, it can be easy to forget to `await` a promise |
| 6 | which can result in async tasks running in an unexpected order. Thus, we require |
| 7 | that every promise in an `async` function is consumed in some way, so that |
| 8 | there's a well-defined order in which async tasks are resolved. To fix this |
| 9 | check, you can do one of the following: |
| 10 | |
| 11 | 1. Remove `async` from the function, and instead use normal promise chaining. |
| 12 | 2. `await` the promise. |
| 13 | 3. Assign the promise to a variable and `await` it later. |
| 14 | |
| 15 | As a last resort, if you really want to use `async` and can't `await` the promise, |
| 16 | you can just assign it to a variable, like so |
| 17 | |
| 18 | let ignoredPromise = returnsPromise(); |
| 19 | |
| 20 | This makes your intent to ignore the result of the promise explicit, although it |
| 21 | may cause "declared but never used" warning with some linters. |