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