(type)
| 81351 | type; |
| 81352 | } |
| 81353 | function createAwaitedTypeIfNeeded(type) { |
| 81354 | // We wrap type `T` in `Awaited<T>` based on the following conditions: |
| 81355 | // - `T` is not already an `Awaited<U>`, and |
| 81356 | // - `T` is generic, and |
| 81357 | // - One of the following applies: |
| 81358 | // - `T` has no base constraint, or |
| 81359 | // - The base constraint of `T` is `any`, `unknown`, `object`, or `{}`, or |
| 81360 | // - The base constraint of `T` is an object type with a callable `then` method. |
| 81361 | if (isTypeAny(type)) { |
| 81362 | return type; |
| 81363 | } |
| 81364 | // If this is already an `Awaited<T>`, just return it. This helps to avoid `Awaited<Awaited<T>>` in higher-order. |
| 81365 | if (isAwaitedTypeInstantiation(type)) { |
| 81366 | return type; |
| 81367 | } |
| 81368 | // Only instantiate `Awaited<T>` if `T` contains possibly non-primitive types. |
| 81369 | if (isGenericObjectType(type)) { |
| 81370 | var baseConstraint = getBaseConstraintOfType(type); |
| 81371 | // Only instantiate `Awaited<T>` if `T` has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`, |
| 81372 | // or is promise-like. |
| 81373 | if (!baseConstraint || (baseConstraint.flags & 3 /* TypeFlags.AnyOrUnknown */) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) { |
| 81374 | // Nothing to do if `Awaited<T>` doesn't exist |
| 81375 | var awaitedSymbol = getGlobalAwaitedSymbol(/*reportErrors*/ true); |
| 81376 | if (awaitedSymbol) { |
| 81377 | // Unwrap unions that may contain `Awaited<T>`, otherwise its possible to manufacture an `Awaited<Awaited<T> | U>` where |
| 81378 | // an `Awaited<T | U>` would suffice. |
| 81379 | return getTypeAliasInstantiation(awaitedSymbol, [unwrapAwaitedType(type)]); |
| 81380 | } |
| 81381 | } |
| 81382 | } |
| 81383 | ts.Debug.assert(getPromisedTypeOfPromise(type) === undefined, "type provided should not be a non-generic 'promise'-like."); |
| 81384 | return type; |
| 81385 | } |
| 81386 | /** |
| 81387 | * Gets the "awaited type" of a type. |
| 81388 | * |
no test coverage detected