Simplify a branch of the Awaited type and clean up comments (#45918)

This commit is contained in:
Ron Buckton 2021-09-16 18:04:09 -04:00 committed by GitHub
parent 6aaefe41fe
commit b23f44aee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

12
src/lib/es5.d.ts vendored
View File

@ -1477,13 +1477,11 @@ interface Promise<T> {
*/
type Awaited<T> =
T extends null | undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` mode
T extends object ? // `await` only unwraps object types with a callable then. Non-object types are not unwrapped.
T extends { then(onfulfilled: infer F): any } ? // thenable, extracts the first argument to `then()`
F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument
Awaited<V> : // recursively unwrap the value
never : // the argument to `then` was not callable.
T : // argument was not an object
T; // non-thenable
T extends object & { then(onfulfilled: infer F): any } ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument
Awaited<V> : // recursively unwrap the value
never : // the argument to `then` was not callable
T; // non-object or non-thenable
interface ArrayLike<T> {
readonly length: number;