Adds 'Awaited' type alias and updates to Promise.all/race/allSettled/any (#45350)

* Adds 'Awaited' type alias and updates to Promise.all/race/allSettled/any

* Use Awaited<T> with 'await'

* Clean up overloads

* Further restrict 'Awaited<T>' auto-wrapping for 'await'
This commit is contained in:
Ron Buckton 2021-09-09 18:23:17 -07:00 committed by GitHub
parent cdd93149f3
commit ea521d45e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 2142 additions and 290 deletions

View file

@ -913,28 +913,29 @@ namespace ts {
// and they will not get an error from not having unrelated library files
let deferredGlobalESSymbolConstructorSymbol: Symbol | undefined;
let deferredGlobalESSymbolConstructorTypeSymbol: Symbol | undefined;
let deferredGlobalESSymbolType: ObjectType;
let deferredGlobalESSymbolType: ObjectType | undefined;
let deferredGlobalTypedPropertyDescriptorType: GenericType;
let deferredGlobalPromiseType: GenericType;
let deferredGlobalPromiseLikeType: GenericType;
let deferredGlobalPromiseType: GenericType | undefined;
let deferredGlobalPromiseLikeType: GenericType | undefined;
let deferredGlobalPromiseConstructorSymbol: Symbol | undefined;
let deferredGlobalPromiseConstructorLikeType: ObjectType;
let deferredGlobalIterableType: GenericType;
let deferredGlobalIteratorType: GenericType;
let deferredGlobalIterableIteratorType: GenericType;
let deferredGlobalGeneratorType: GenericType;
let deferredGlobalIteratorYieldResultType: GenericType;
let deferredGlobalIteratorReturnResultType: GenericType;
let deferredGlobalAsyncIterableType: GenericType;
let deferredGlobalAsyncIteratorType: GenericType;
let deferredGlobalAsyncIterableIteratorType: GenericType;
let deferredGlobalAsyncGeneratorType: GenericType;
let deferredGlobalTemplateStringsArrayType: ObjectType;
let deferredGlobalPromiseConstructorLikeType: ObjectType | undefined;
let deferredGlobalIterableType: GenericType | undefined;
let deferredGlobalIteratorType: GenericType | undefined;
let deferredGlobalIterableIteratorType: GenericType | undefined;
let deferredGlobalGeneratorType: GenericType | undefined;
let deferredGlobalIteratorYieldResultType: GenericType | undefined;
let deferredGlobalIteratorReturnResultType: GenericType | undefined;
let deferredGlobalAsyncIterableType: GenericType | undefined;
let deferredGlobalAsyncIteratorType: GenericType | undefined;
let deferredGlobalAsyncIterableIteratorType: GenericType | undefined;
let deferredGlobalAsyncGeneratorType: GenericType | undefined;
let deferredGlobalTemplateStringsArrayType: ObjectType | undefined;
let deferredGlobalImportMetaType: ObjectType;
let deferredGlobalImportMetaExpressionType: ObjectType;
let deferredGlobalExtractSymbol: Symbol;
let deferredGlobalOmitSymbol: Symbol;
let deferredGlobalBigIntType: ObjectType;
let deferredGlobalExtractSymbol: Symbol | undefined;
let deferredGlobalOmitSymbol: Symbol | undefined;
let deferredGlobalAwaitedSymbol: Symbol | undefined;
let deferredGlobalBigIntType: ObjectType | undefined;
const allPotentiallyUnusedIdentifiers = new Map<Path, PotentiallyUnusedIdentifier[]>(); // key is file name
@ -13391,28 +13392,48 @@ namespace ts {
return getGlobalSymbol(name, SymbolFlags.Type, reportErrors ? Diagnostics.Cannot_find_global_type_0 : undefined);
}
function getGlobalTypeAliasSymbol(name: __String, arity: number, reportErrors: boolean): Symbol | undefined {
const symbol = getGlobalSymbol(name, SymbolFlags.Type, reportErrors ? Diagnostics.Cannot_find_global_type_0 : undefined);
if (symbol) {
// Resolve the declared type of the symbol. This resolves type parameters for the type
// alias so that we can check arity.
getDeclaredTypeOfSymbol(symbol);
if (length(getSymbolLinks(symbol).typeParameters) !== arity) {
const decl = symbol.declarations && find(symbol.declarations, isTypeAliasDeclaration);
error(decl, Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbolName(symbol), arity);
return undefined;
}
}
return symbol;
}
function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined {
// Don't track references for global symbols anyway, so value if `isReference` is arbitrary
return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false);
}
function getGlobalType(name: __String, arity: 0, reportErrors: boolean): ObjectType;
function getGlobalType(name: __String, arity: number, reportErrors: boolean): GenericType;
function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType;
function getGlobalType(name: __String, arity: 0, reportErrors: boolean): ObjectType | undefined;
function getGlobalType(name: __String, arity: number, reportErrors: true): GenericType;
function getGlobalType(name: __String, arity: number, reportErrors: boolean): GenericType | undefined;
function getGlobalType(name: __String, arity: number, reportErrors: boolean): ObjectType | undefined {
const symbol = getGlobalTypeSymbol(name, reportErrors);
return symbol || reportErrors ? getTypeOfGlobalSymbol(symbol, arity) : undefined;
}
function getGlobalTypedPropertyDescriptorType() {
return deferredGlobalTypedPropertyDescriptorType || (deferredGlobalTypedPropertyDescriptorType = getGlobalType("TypedPropertyDescriptor" as __String, /*arity*/ 1, /*reportErrors*/ true)) || emptyGenericType;
// We always report an error, so store a result in the event we could not resolve the symbol to prevent reporting it multiple times
return deferredGlobalTypedPropertyDescriptorType ||= getGlobalType("TypedPropertyDescriptor" as __String, /*arity*/ 1, /*reportErrors*/ true) || emptyGenericType;
}
function getGlobalTemplateStringsArrayType() {
return deferredGlobalTemplateStringsArrayType || (deferredGlobalTemplateStringsArrayType = getGlobalType("TemplateStringsArray" as __String, /*arity*/ 0, /*reportErrors*/ true)) || emptyObjectType;
// We always report an error, so store a result in the event we could not resolve the symbol to prevent reporting it multiple times
return deferredGlobalTemplateStringsArrayType ||= getGlobalType("TemplateStringsArray" as __String, /*arity*/ 0, /*reportErrors*/ true) || emptyObjectType;
}
function getGlobalImportMetaType() {
return deferredGlobalImportMetaType || (deferredGlobalImportMetaType = getGlobalType("ImportMeta" as __String, /*arity*/ 0, /*reportErrors*/ true)) || emptyObjectType;
// We always report an error, so store a result in the event we could not resolve the symbol to prevent reporting it multiple times
return deferredGlobalImportMetaType ||= getGlobalType("ImportMeta" as __String, /*arity*/ 0, /*reportErrors*/ true) || emptyObjectType;
}
function getGlobalImportMetaExpressionType() {
@ -13433,72 +13454,72 @@ namespace ts {
return deferredGlobalImportMetaExpressionType;
}
function getGlobalESSymbolConstructorSymbol(reportErrors: boolean) {
return deferredGlobalESSymbolConstructorSymbol || (deferredGlobalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol" as __String, reportErrors));
function getGlobalESSymbolConstructorSymbol(reportErrors: boolean): Symbol | undefined {
return deferredGlobalESSymbolConstructorSymbol ||= getGlobalValueSymbol("Symbol" as __String, reportErrors);
}
function getGlobalESSymbolConstructorTypeSymbol(reportErrors: boolean) {
return deferredGlobalESSymbolConstructorTypeSymbol || (deferredGlobalESSymbolConstructorTypeSymbol = getGlobalTypeSymbol("SymbolConstructor" as __String, reportErrors));
function getGlobalESSymbolConstructorTypeSymbol(reportErrors: boolean): Symbol | undefined {
return deferredGlobalESSymbolConstructorTypeSymbol ||= getGlobalTypeSymbol("SymbolConstructor" as __String, reportErrors);
}
function getGlobalESSymbolType(reportErrors: boolean) {
return deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType;
return (deferredGlobalESSymbolType ||= getGlobalType("Symbol" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType;
}
function getGlobalPromiseType(reportErrors: boolean) {
return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
return (deferredGlobalPromiseType ||= getGlobalType("Promise" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalPromiseLikeType(reportErrors: boolean) {
return deferredGlobalPromiseLikeType || (deferredGlobalPromiseLikeType = getGlobalType("PromiseLike" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
return (deferredGlobalPromiseLikeType ||= getGlobalType("PromiseLike" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalPromiseConstructorSymbol(reportErrors: boolean): Symbol | undefined {
return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise" as __String, reportErrors));
return deferredGlobalPromiseConstructorSymbol ||= getGlobalValueSymbol("Promise" as __String, reportErrors);
}
function getGlobalPromiseConstructorLikeType(reportErrors: boolean) {
return deferredGlobalPromiseConstructorLikeType || (deferredGlobalPromiseConstructorLikeType = getGlobalType("PromiseConstructorLike" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType;
return (deferredGlobalPromiseConstructorLikeType ||= getGlobalType("PromiseConstructorLike" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType;
}
function getGlobalAsyncIterableType(reportErrors: boolean) {
return deferredGlobalAsyncIterableType || (deferredGlobalAsyncIterableType = getGlobalType("AsyncIterable" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
return (deferredGlobalAsyncIterableType ||= getGlobalType("AsyncIterable" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalAsyncIteratorType(reportErrors: boolean) {
return deferredGlobalAsyncIteratorType || (deferredGlobalAsyncIteratorType = getGlobalType("AsyncIterator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType;
return (deferredGlobalAsyncIteratorType ||= getGlobalType("AsyncIterator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType;
}
function getGlobalAsyncIterableIteratorType(reportErrors: boolean) {
return deferredGlobalAsyncIterableIteratorType || (deferredGlobalAsyncIterableIteratorType = getGlobalType("AsyncIterableIterator" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
return (deferredGlobalAsyncIterableIteratorType ||= getGlobalType("AsyncIterableIterator" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalAsyncGeneratorType(reportErrors: boolean) {
return deferredGlobalAsyncGeneratorType || (deferredGlobalAsyncGeneratorType = getGlobalType("AsyncGenerator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType;
return (deferredGlobalAsyncGeneratorType ||= getGlobalType("AsyncGenerator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType;
}
function getGlobalIterableType(reportErrors: boolean) {
return deferredGlobalIterableType || (deferredGlobalIterableType = getGlobalType("Iterable" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
return (deferredGlobalIterableType ||= getGlobalType("Iterable" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalIteratorType(reportErrors: boolean) {
return deferredGlobalIteratorType || (deferredGlobalIteratorType = getGlobalType("Iterator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType;
return (deferredGlobalIteratorType ||= getGlobalType("Iterator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType;
}
function getGlobalIterableIteratorType(reportErrors: boolean) {
return deferredGlobalIterableIteratorType || (deferredGlobalIterableIteratorType = getGlobalType("IterableIterator" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
return (deferredGlobalIterableIteratorType ||= getGlobalType("IterableIterator" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalGeneratorType(reportErrors: boolean) {
return deferredGlobalGeneratorType || (deferredGlobalGeneratorType = getGlobalType("Generator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType;
return (deferredGlobalGeneratorType ||= getGlobalType("Generator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType;
}
function getGlobalIteratorYieldResultType(reportErrors: boolean) {
return deferredGlobalIteratorYieldResultType || (deferredGlobalIteratorYieldResultType = getGlobalType("IteratorYieldResult" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
return (deferredGlobalIteratorYieldResultType ||= getGlobalType("IteratorYieldResult" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalIteratorReturnResultType(reportErrors: boolean) {
return deferredGlobalIteratorReturnResultType || (deferredGlobalIteratorReturnResultType = getGlobalType("IteratorReturnResult" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
return (deferredGlobalIteratorReturnResultType ||= getGlobalType("IteratorReturnResult" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalTypeOrUndefined(name: __String, arity = 0): ObjectType | undefined {
@ -13506,16 +13527,26 @@ namespace ts {
return symbol && getTypeOfGlobalSymbol(symbol, arity) as GenericType;
}
function getGlobalExtractSymbol(): Symbol {
return deferredGlobalExtractSymbol || (deferredGlobalExtractSymbol = getGlobalSymbol("Extract" as __String, SymbolFlags.TypeAlias, Diagnostics.Cannot_find_global_type_0)!); // TODO: GH#18217
function getGlobalExtractSymbol(): Symbol | undefined {
// We always report an error, so cache a result in the event we could not resolve the symbol to prevent reporting it multiple times
deferredGlobalExtractSymbol ||= getGlobalTypeAliasSymbol("Extract" as __String, /*arity*/ 2, /*reportErrors*/ true) || unknownSymbol;
return deferredGlobalExtractSymbol === unknownSymbol ? undefined : deferredGlobalExtractSymbol;
}
function getGlobalOmitSymbol(): Symbol {
return deferredGlobalOmitSymbol || (deferredGlobalOmitSymbol = getGlobalSymbol("Omit" as __String, SymbolFlags.TypeAlias, Diagnostics.Cannot_find_global_type_0)!); // TODO: GH#18217
function getGlobalOmitSymbol(): Symbol | undefined {
// We always report an error, so cache a result in the event we could not resolve the symbol to prevent reporting it multiple times
deferredGlobalOmitSymbol ||= getGlobalTypeAliasSymbol("Omit" as __String, /*arity*/ 2, /*reportErrors*/ true) || unknownSymbol;
return deferredGlobalOmitSymbol === unknownSymbol ? undefined : deferredGlobalOmitSymbol;
}
function getGlobalAwaitedSymbol(reportErrors: boolean): Symbol | undefined {
// Only cache `unknownSymbol` if we are reporting errors so that we don't report the error more than once.
deferredGlobalAwaitedSymbol ||= getGlobalTypeAliasSymbol("Awaited" as __String, /*arity*/ 1, reportErrors) || (reportErrors ? unknownSymbol : undefined);
return deferredGlobalAwaitedSymbol === unknownSymbol ? undefined : deferredGlobalAwaitedSymbol;
}
function getGlobalBigIntType(reportErrors: boolean) {
return deferredGlobalBigIntType || (deferredGlobalBigIntType = getGlobalType("BigInt" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType;
return (deferredGlobalBigIntType ||= getGlobalType("BigInt" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType;
}
/**
@ -25405,8 +25436,9 @@ namespace ts {
}
if (functionFlags & FunctionFlags.Async) { // Async function or AsyncGenerator function
// Get the awaited type without the `Awaited<T>` alias
const contextualAwaitedType = mapType(contextualReturnType, getAwaitedType);
return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]);
return contextualAwaitedType && getUnionType([unwrapAwaitedType(contextualAwaitedType), createPromiseLikeType(contextualAwaitedType)]);
}
return contextualReturnType; // Regular function or Generator function
@ -25419,7 +25451,7 @@ namespace ts {
const contextualType = getContextualType(node, contextFlags);
if (contextualType) {
const contextualAwaitedType = getAwaitedType(contextualType);
return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]);
return contextualAwaitedType && getUnionType([unwrapAwaitedType(contextualAwaitedType), createPromiseLikeType(contextualAwaitedType)]);
}
return undefined;
}
@ -32751,8 +32783,8 @@ namespace ts {
let wouldWorkWithAwait = false;
const errNode = errorNode || operatorToken;
if (isRelated) {
const awaitedLeftType = getAwaitedType(leftType);
const awaitedRightType = getAwaitedType(rightType);
const awaitedLeftType = unwrapAwaitedType(getAwaitedType(leftType));
const awaitedRightType = unwrapAwaitedType(getAwaitedType(rightType));
wouldWorkWithAwait = !(awaitedLeftType === leftType && awaitedRightType === rightType)
&& !!(awaitedLeftType && awaitedRightType)
&& isRelated(awaitedLeftType, awaitedRightType);
@ -34797,6 +34829,11 @@ namespace ts {
return typeAsPromise.promisedTypeOfPromise = getTypeArguments(type as GenericType)[0];
}
// primitives with a `{ then() }` won't be unwrapped/adopted.
if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) {
return undefined;
}
const thenFunction = getTypeOfPropertyOfType(type, "then" as __String)!; // TODO: GH#18217
if (isTypeAny(thenFunction)) {
return undefined;
@ -34839,13 +34876,82 @@ namespace ts {
}
/**
* Determines whether a type has a callable `then` member.
* Determines whether a type is an object with a callable `then` member.
*/
function isThenableType(type: Type): boolean {
if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) {
// primitive types cannot be considered "thenable" since they are not objects.
return false;
}
const thenFunction = getTypeOfPropertyOfType(type, "then" as __String);
return !!thenFunction && getSignaturesOfType(getTypeWithFacts(thenFunction, TypeFacts.NEUndefinedOrNull), SignatureKind.Call).length > 0;
}
interface AwaitedTypeInstantiation extends Type {
_awaitedTypeBrand: never;
aliasSymbol: Symbol;
aliasTypeArguments: readonly Type[];
}
function isAwaitedTypeInstantiation(type: Type): type is AwaitedTypeInstantiation {
if (type.flags & TypeFlags.Conditional) {
const awaitedSymbol = getGlobalAwaitedSymbol(/*reportErrors*/ false);
return !!awaitedSymbol && type.aliasSymbol === awaitedSymbol && type.aliasTypeArguments?.length === 1;
}
return false;
}
/**
* For a generic `Awaited<T>`, gets `T`.
*/
function unwrapAwaitedType(type: Type): Type;
function unwrapAwaitedType(type: Type | undefined): Type | undefined;
function unwrapAwaitedType(type: Type | undefined) {
if (!type) return undefined;
return type.flags & TypeFlags.Union ? mapType(type, unwrapAwaitedType) :
isAwaitedTypeInstantiation(type) ? type.aliasTypeArguments[0] :
type;
}
function createAwaitedTypeIfNeeded(type: Type): Type {
// We wrap type `T` in `Awaited<T>` based on the following conditions:
// - `T` is not already an `Awaited<U>`, and
// - `T` is generic, and
// - One of the following applies:
// - `T` has no base constraint, or
// - The base constraint of `T` is `any`, `unknown`, `object`, or `{}`, or
// - The base constraint of `T` is an object type with a callable `then` method.
if (isTypeAny(type)) {
return type;
}
// If this is already an `Awaited<T>`, just return it. This helps to avoid `Awaited<Awaited<T>>` in higher-order.
if (isAwaitedTypeInstantiation(type)) {
return type;
}
// Only instantiate `Awaited<T>` if `T` contains possibly non-primitive types.
if (isGenericObjectType(type)) {
const baseConstraint = getBaseConstraintOfType(type);
// Only instantiate `Awaited<T>` if `T` has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`,
// or is promise-like.
if (!baseConstraint || (baseConstraint.flags & TypeFlags.AnyOrUnknown) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
// Nothing to do if `Awaited<T>` doesn't exist
const awaitedSymbol = getGlobalAwaitedSymbol(/*reportErrors*/ true);
if (awaitedSymbol) {
// Unwrap unions that may contain `Awaited<T>`, otherwise its possible to manufacture an `Awaited<Awaited<T> | U>` where
// an `Awaited<T | U>` would suffice.
return getTypeAliasInstantiation(awaitedSymbol, [unwrapAwaitedType(type)]);
}
}
}
Debug.assert(getPromisedTypeOfPromise(type) === undefined, "type provided should not be a non-generic 'promise'-like.");
return type;
}
/**
* Gets the "awaited type" of a type.
*
@ -34861,21 +34967,22 @@ namespace ts {
return type;
}
// If this is already an `Awaited<T>`, just return it. This avoids `Awaited<Awaited<T>>` in higher-order
if (isAwaitedTypeInstantiation(type)) {
return type;
}
// If we've already cached an awaited type, return a possible `Awaited<T>` for it.
const typeAsAwaitable = type as PromiseOrAwaitableType;
if (typeAsAwaitable.awaitedTypeOfType) {
return typeAsAwaitable.awaitedTypeOfType;
return createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType);
}
// For a union, get a union of the awaited types of each constituent.
//
return typeAsAwaitable.awaitedTypeOfType =
mapType(type, errorNode ? constituentType => getAwaitedTypeWorker(constituentType, errorNode, diagnosticMessage, arg0) : getAwaitedTypeWorker);
}
function getAwaitedTypeWorker(type: Type, errorNode?: Node, diagnosticMessage?: DiagnosticMessage, arg0?: string | number): Type | undefined {
const typeAsAwaitable = type as PromiseOrAwaitableType;
if (typeAsAwaitable.awaitedTypeOfType) {
return typeAsAwaitable.awaitedTypeOfType;
if (type.flags & TypeFlags.Union) {
const mapper = errorNode ? (constituentType: Type) => getAwaitedType(constituentType, errorNode, diagnosticMessage, arg0) : getAwaitedType;
typeAsAwaitable.awaitedTypeOfType = mapType(type, mapper);
return typeAsAwaitable.awaitedTypeOfType && createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType);
}
const promisedType = getPromisedTypeOfPromise(type);
@ -34930,7 +35037,7 @@ namespace ts {
return undefined;
}
return typeAsAwaitable.awaitedTypeOfType = awaitedType;
return createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType = awaitedType);
}
// The type was not a promise, so it could not be unwrapped any further.
@ -34950,13 +35057,13 @@ namespace ts {
// be treated as a promise, they can cast to <any>.
if (isThenableType(type)) {
if (errorNode) {
if (!diagnosticMessage) return Debug.fail();
Debug.assertIsDefined(diagnosticMessage);
error(errorNode, diagnosticMessage, arg0);
}
return undefined;
}
return typeAsAwaitable.awaitedTypeOfType = type;
return createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType = type);
}
/**
@ -35006,7 +35113,7 @@ namespace ts {
if (globalPromiseType !== emptyGenericType && !isReferenceToType(returnType, globalPromiseType)) {
// The promise type was not a valid type reference to the global promise type, so we
// report an error and return the unknown type.
error(returnTypeNode, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type_Did_you_mean_to_write_Promise_0, typeToString(getAwaitedType(returnType) || voidType));
error(returnTypeNode, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type_Did_you_mean_to_write_Promise_0, typeToString(unwrapAwaitedType(getAwaitedType(returnType)) || voidType));
return;
}
}
@ -36878,6 +36985,10 @@ namespace ts {
if (iterationTypes === noIterationTypes) return noIterationTypes;
if (iterationTypes === anyIterationTypes) return anyIterationTypes;
const { yieldType, returnType, nextType } = iterationTypes;
// if we're requesting diagnostics, report errors for a missing `Awaited<T>`.
if (errorNode) {
getGlobalAwaitedSymbol(/*reportErrors*/ true);
}
return createIterationTypes(
getAwaitedType(yieldType, errorNode) || anyType,
getAwaitedType(returnType, errorNode) || anyType,
@ -36904,7 +37015,9 @@ namespace ts {
getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
if (iterationTypes) {
return iterationTypes;
return use & IterationUse.ForOfFlag ?
getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
iterationTypes;
}
}
@ -36993,7 +37106,7 @@ namespace ts {
// While we define these as `any` and `undefined` in our libs by default, a custom lib *could* use
// different definitions.
const { returnType, nextType } = getIterationTypesOfGlobalIterableType(globalType, resolver);
return setCachedIterationTypes(type, resolver.iterableCacheKey, createIterationTypes(yieldType, returnType, nextType));
return setCachedIterationTypes(type, resolver.iterableCacheKey, createIterationTypes(resolver.resolveIterationType(yieldType, /*errorNode*/ undefined) || yieldType, resolver.resolveIterationType(returnType, /*errorNode*/ undefined) || returnType, nextType));
}
// As an optimization, if the type is an instantiation of the following global type, then
@ -37001,7 +37114,7 @@ namespace ts {
// - `Generator<T, TReturn, TNext>` or `AsyncGenerator<T, TReturn, TNext>`
if (isReferenceToType(type, resolver.getGlobalGeneratorType(/*reportErrors*/ false))) {
const [yieldType, returnType, nextType] = getTypeArguments(type as GenericType);
return setCachedIterationTypes(type, resolver.iterableCacheKey, createIterationTypes(yieldType, returnType, nextType));
return setCachedIterationTypes(type, resolver.iterableCacheKey, createIterationTypes(resolver.resolveIterationType(yieldType, /*errorNode*/ undefined) || yieldType, resolver.resolveIterationType(returnType, /*errorNode*/ undefined) || returnType, nextType));
}
}
@ -37333,8 +37446,8 @@ namespace ts {
function unwrapReturnType(returnType: Type, functionFlags: FunctionFlags) {
const isGenerator = !!(functionFlags & FunctionFlags.Generator);
const isAsync = !!(functionFlags & FunctionFlags.Async);
return isGenerator ? getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, isAsync) ?? errorType :
isAsync ? getAwaitedType(returnType) ?? errorType :
return isGenerator ? getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, isAsync) || errorType :
isAsync ? unwrapAwaitedType(getAwaitedType(returnType)) || errorType :
returnType;
}

View file

@ -1095,6 +1095,7 @@ namespace FourSlashInterface {
typeEntry("PromiseConstructorLike"),
interfaceEntry("PromiseLike"),
interfaceEntry("Promise"),
typeEntry("Awaited"),
interfaceEntry("ArrayLike"),
typeEntry("Partial"),
typeEntry("Required"),

View file

@ -203,7 +203,7 @@ interface PromiseConstructor {
* @param values An iterable of Promises.
* @returns A new Promise.
*/
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
@ -211,15 +211,7 @@ interface PromiseConstructor {
* @param values An iterable of Promises.
* @returns A new Promise.
*/
race<T>(values: Iterable<T>): Promise<T extends PromiseLike<infer U> ? U : T>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An iterable of Promises.
* @returns A new Promise.
*/
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
}
interface String {

View file

@ -18,79 +18,7 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]> }>;
// see: lib.es2015.iterable.d.ts
// all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
@ -101,7 +29,7 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T>(values: readonly T[]): Promise<T extends PromiseLike<infer U> ? U : T>;
race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
// see: lib.es2015.iterable.d.ts
// race<T>(values: Iterable<T>): Promise<T extends PromiseLike<infer U> ? U : T>;

View file

@ -17,8 +17,7 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
allSettled<T extends readonly unknown[] | readonly [unknown]>(values: T):
Promise<{ -readonly [P in keyof T]: PromiseSettledResult<T[P] extends PromiseLike<infer U> ? U : T[P]> }>;
allSettled<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: PromiseSettledResult<Awaited<T[P]>> }>;
/**
* Creates a Promise that is resolved with an array of results when all
@ -26,5 +25,5 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
allSettled<T>(values: Iterable<T>): Promise<PromiseSettledResult<T extends PromiseLike<infer U> ? U : T>[]>;
allSettled<T>(values: Iterable<T | PromiseLike<T>>): Promise<PromiseSettledResult<Awaited<T>>[]>;
}

View file

@ -19,5 +19,12 @@ interface PromiseConstructor {
* @param values An array or iterable of Promises.
* @returns A new Promise.
*/
any<T>(values: (T | PromiseLike<T>)[] | Iterable<T | PromiseLike<T>>): Promise<T>
any<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
/**
* The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.
* @param values An array or iterable of Promises.
* @returns A new Promise.
*/
any<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>
}

13
src/lib/es5.d.ts vendored
View file

@ -1472,6 +1472,19 @@ interface Promise<T> {
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
}
/**
* Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`.
*/
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
interface ArrayLike<T> {
readonly length: number;
readonly [n: number]: T;

View file

@ -16,7 +16,7 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction9_es20
!!! error TS1005: ',' expected.
~~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'.
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:150:13: 'Promise' was also declared here.
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:78:13: 'Promise' was also declared here.
~
!!! error TS1005: ',' expected.
~~

View file

@ -16,7 +16,7 @@ tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(
!!! error TS1005: ',' expected.
~~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'.
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:150:13: 'Promise' was also declared here.
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:78:13: 'Promise' was also declared here.
~
!!! error TS1005: ',' expected.
~~

View file

@ -16,7 +16,7 @@ tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(
!!! error TS1005: ',' expected.
~~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'.
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:150:13: 'Promise' was also declared here.
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:78:13: 'Promise' was also declared here.
~
!!! error TS1005: ',' expected.
~~

View file

@ -0,0 +1,168 @@
tests/cases/compiler/awaitedType.ts(18,12): error TS2589: Type instantiation is excessively deep and possibly infinite.
tests/cases/compiler/awaitedType.ts(22,12): error TS2589: Type instantiation is excessively deep and possibly infinite.
==== tests/cases/compiler/awaitedType.ts (2 errors) ====
type T1 = Awaited<number>;
type T2 = Awaited<Promise<number>>;
type T3 = Awaited<number | Promise<number>>;
type T4 = Awaited<number | Promise<string>>;
type T5 = Awaited<{ then: number }>;
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
type T9 = Awaited<any>;
type T10 = Awaited<never>;
type T11 = Awaited<unknown>;
type T12 = Awaited<Promise<Promise<number>>>;
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
type T16 = Awaited<BadPromise>; // error
~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error
~~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
async function main() {
let aaa: number;
let bbb: string;
[
aaa,
bbb,
] = await Promise.all([
MaybePromise(1),
MaybePromise('2'),
MaybePromise(true),
])
}
// non-generic
async function f1(x: string) {
// y: string
const y = await x;
}
async function f2(x: unknown) {
// y: unknown
const y = await x;
}
async function f3(x: object) {
// y: object
const y = await x;
}
async function f4(x: Promise<string>) {
// y: string
const y = await x;
}
async function f5(x: Promise<unknown>) {
// y: unknown
const y = await x;
}
async function f6(x: Promise<object>) {
// y: object
const y = await x;
}
// generic
async function f7<T>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f8<T extends any>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f9<T extends unknown>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f10<T extends {}>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f11<T extends { then(onfulfilled: (value: unknown) => void): void }>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f12<T extends string | object>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f13<T extends string>(x: T) {
// NOTE: T belongs to the domain of primitive types
// y: T
const y = await x;
}
async function f14<T extends { x: number }>(x: T) {
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
}
async function f15<T extends { then: number }>(x: T) {
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
}
async function f16<T extends number & { then(): void }>(x: T) {
// NOTE: T belongs to the domain of primitive types (regardless of `then`)
// y: T
const y = await x;
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;

View file

@ -0,0 +1,262 @@
//// [awaitedType.ts]
type T1 = Awaited<number>;
type T2 = Awaited<Promise<number>>;
type T3 = Awaited<number | Promise<number>>;
type T4 = Awaited<number | Promise<string>>;
type T5 = Awaited<{ then: number }>;
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
type T9 = Awaited<any>;
type T10 = Awaited<never>;
type T11 = Awaited<unknown>;
type T12 = Awaited<Promise<Promise<number>>>;
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
type T16 = Awaited<BadPromise>; // error
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
async function main() {
let aaa: number;
let bbb: string;
[
aaa,
bbb,
] = await Promise.all([
MaybePromise(1),
MaybePromise('2'),
MaybePromise(true),
])
}
// non-generic
async function f1(x: string) {
// y: string
const y = await x;
}
async function f2(x: unknown) {
// y: unknown
const y = await x;
}
async function f3(x: object) {
// y: object
const y = await x;
}
async function f4(x: Promise<string>) {
// y: string
const y = await x;
}
async function f5(x: Promise<unknown>) {
// y: unknown
const y = await x;
}
async function f6(x: Promise<object>) {
// y: object
const y = await x;
}
// generic
async function f7<T>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f8<T extends any>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f9<T extends unknown>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f10<T extends {}>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f11<T extends { then(onfulfilled: (value: unknown) => void): void }>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f12<T extends string | object>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f13<T extends string>(x: T) {
// NOTE: T belongs to the domain of primitive types
// y: T
const y = await x;
}
async function f14<T extends { x: number }>(x: T) {
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
}
async function f15<T extends { then: number }>(x: T) {
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
}
async function f16<T extends number & { then(): void }>(x: T) {
// NOTE: T belongs to the domain of primitive types (regardless of `then`)
// y: T
const y = await x;
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;
//// [awaitedType.js]
async function main() {
let aaa;
let bbb;
[
aaa,
bbb,
] = await Promise.all([
MaybePromise(1),
MaybePromise('2'),
MaybePromise(true),
]);
}
// non-generic
async function f1(x) {
// y: string
const y = await x;
}
async function f2(x) {
// y: unknown
const y = await x;
}
async function f3(x) {
// y: object
const y = await x;
}
async function f4(x) {
// y: string
const y = await x;
}
async function f5(x) {
// y: unknown
const y = await x;
}
async function f6(x) {
// y: object
const y = await x;
}
// generic
async function f7(x) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f8(x) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f9(x) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f10(x) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f11(x) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f12(x) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f13(x) {
// NOTE: T belongs to the domain of primitive types
// y: T
const y = await x;
}
async function f14(x) {
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
}
async function f15(x) {
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
}
async function f16(x) {
// NOTE: T belongs to the domain of primitive types (regardless of `then`)
// y: T
const y = await x;
}

View file

@ -0,0 +1,396 @@
=== tests/cases/compiler/awaitedType.ts ===
type T1 = Awaited<number>;
>T1 : Symbol(T1, Decl(awaitedType.ts, 0, 0))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
type T2 = Awaited<Promise<number>>;
>T2 : Symbol(T2, Decl(awaitedType.ts, 0, 26))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T3 = Awaited<number | Promise<number>>;
>T3 : Symbol(T3, Decl(awaitedType.ts, 1, 35))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T4 = Awaited<number | Promise<string>>;
>T4 : Symbol(T4, Decl(awaitedType.ts, 2, 44))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T5 = Awaited<{ then: number }>;
>T5 : Symbol(T5, Decl(awaitedType.ts, 3, 44))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedType.ts, 4, 19))
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
>T6 : Symbol(T6, Decl(awaitedType.ts, 4, 36))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedType.ts, 5, 19))
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
>T7 : Symbol(T7, Decl(awaitedType.ts, 5, 36))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedType.ts, 6, 19))
>x : Symbol(x, Decl(awaitedType.ts, 6, 25))
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
>T8 : Symbol(T8, Decl(awaitedType.ts, 6, 45))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedType.ts, 7, 19))
>x : Symbol(x, Decl(awaitedType.ts, 7, 25))
type T9 = Awaited<any>;
>T9 : Symbol(T9, Decl(awaitedType.ts, 7, 49))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
type T10 = Awaited<never>;
>T10 : Symbol(T10, Decl(awaitedType.ts, 8, 23))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
type T11 = Awaited<unknown>;
>T11 : Symbol(T11, Decl(awaitedType.ts, 9, 26))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
type T12 = Awaited<Promise<Promise<number>>>;
>T12 : Symbol(T12, Decl(awaitedType.ts, 10, 28))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
>T13 : Symbol(T13, Decl(awaitedType.ts, 11, 45))
>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 153, 1))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
>T14 : Symbol(T14, Decl(awaitedType.ts, 12, 107))
>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 153, 1))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
>T15 : Symbol(T15, Decl(awaitedType.ts, 13, 117))
>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 153, 1))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
>BadPromise : Symbol(BadPromise, Decl(awaitedType.ts, 14, 131))
>then : Symbol(BadPromise.then, Decl(awaitedType.ts, 16, 22))
>cb : Symbol(cb, Decl(awaitedType.ts, 16, 28))
>value : Symbol(value, Decl(awaitedType.ts, 16, 33))
>BadPromise : Symbol(BadPromise, Decl(awaitedType.ts, 14, 131))
type T16 = Awaited<BadPromise>; // error
>T16 : Symbol(T16, Decl(awaitedType.ts, 16, 69))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>BadPromise : Symbol(BadPromise, Decl(awaitedType.ts, 14, 131))
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
>BadPromise1 : Symbol(BadPromise1, Decl(awaitedType.ts, 17, 31))
>then : Symbol(BadPromise1.then, Decl(awaitedType.ts, 19, 23))
>cb : Symbol(cb, Decl(awaitedType.ts, 19, 29))
>value : Symbol(value, Decl(awaitedType.ts, 19, 34))
>BadPromise2 : Symbol(BadPromise2, Decl(awaitedType.ts, 19, 71))
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
>BadPromise2 : Symbol(BadPromise2, Decl(awaitedType.ts, 19, 71))
>then : Symbol(BadPromise2.then, Decl(awaitedType.ts, 20, 23))
>cb : Symbol(cb, Decl(awaitedType.ts, 20, 29))
>value : Symbol(value, Decl(awaitedType.ts, 20, 34))
>BadPromise1 : Symbol(BadPromise1, Decl(awaitedType.ts, 17, 31))
type T17 = Awaited<BadPromise1>; // error
>T17 : Symbol(T17, Decl(awaitedType.ts, 20, 71))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>BadPromise1 : Symbol(BadPromise1, Decl(awaitedType.ts, 17, 31))
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32))
>T : Symbol(T, Decl(awaitedType.ts, 24, 18))
>T : Symbol(T, Decl(awaitedType.ts, 24, 18))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>T : Symbol(T, Decl(awaitedType.ts, 24, 18))
>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(awaitedType.ts, 24, 18))
declare function MaybePromise<T>(value: T): MaybePromise<T>;
>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32))
>T : Symbol(T, Decl(awaitedType.ts, 25, 30))
>value : Symbol(value, Decl(awaitedType.ts, 25, 33))
>T : Symbol(T, Decl(awaitedType.ts, 25, 30))
>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32))
>T : Symbol(T, Decl(awaitedType.ts, 25, 30))
async function main() {
>main : Symbol(main, Decl(awaitedType.ts, 25, 60))
let aaa: number;
>aaa : Symbol(aaa, Decl(awaitedType.ts, 28, 7))
let bbb: string;
>bbb : Symbol(bbb, Decl(awaitedType.ts, 29, 7))
[
aaa,
>aaa : Symbol(aaa, Decl(awaitedType.ts, 28, 7))
bbb,
>bbb : Symbol(bbb, Decl(awaitedType.ts, 29, 7))
] = await Promise.all([
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
MaybePromise(1),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32))
MaybePromise('2'),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32))
MaybePromise(true),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32))
])
}
// non-generic
async function f1(x: string) {
>f1 : Symbol(f1, Decl(awaitedType.ts, 38, 1))
>x : Symbol(x, Decl(awaitedType.ts, 41, 18))
// y: string
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 43, 9))
>x : Symbol(x, Decl(awaitedType.ts, 41, 18))
}
async function f2(x: unknown) {
>f2 : Symbol(f2, Decl(awaitedType.ts, 44, 1))
>x : Symbol(x, Decl(awaitedType.ts, 46, 18))
// y: unknown
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 48, 9))
>x : Symbol(x, Decl(awaitedType.ts, 46, 18))
}
async function f3(x: object) {
>f3 : Symbol(f3, Decl(awaitedType.ts, 49, 1))
>x : Symbol(x, Decl(awaitedType.ts, 51, 18))
// y: object
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 53, 9))
>x : Symbol(x, Decl(awaitedType.ts, 51, 18))
}
async function f4(x: Promise<string>) {
>f4 : Symbol(f4, Decl(awaitedType.ts, 54, 1))
>x : Symbol(x, Decl(awaitedType.ts, 56, 18))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
// y: string
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 58, 9))
>x : Symbol(x, Decl(awaitedType.ts, 56, 18))
}
async function f5(x: Promise<unknown>) {
>f5 : Symbol(f5, Decl(awaitedType.ts, 59, 1))
>x : Symbol(x, Decl(awaitedType.ts, 61, 18))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
// y: unknown
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 63, 9))
>x : Symbol(x, Decl(awaitedType.ts, 61, 18))
}
async function f6(x: Promise<object>) {
>f6 : Symbol(f6, Decl(awaitedType.ts, 64, 1))
>x : Symbol(x, Decl(awaitedType.ts, 66, 18))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
// y: object
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 68, 9))
>x : Symbol(x, Decl(awaitedType.ts, 66, 18))
}
// generic
async function f7<T>(x: T) {
>f7 : Symbol(f7, Decl(awaitedType.ts, 69, 1))
>T : Symbol(T, Decl(awaitedType.ts, 73, 18))
>x : Symbol(x, Decl(awaitedType.ts, 73, 21))
>T : Symbol(T, Decl(awaitedType.ts, 73, 18))
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 79, 9))
>x : Symbol(x, Decl(awaitedType.ts, 73, 21))
}
async function f8<T extends any>(x: T) {
>f8 : Symbol(f8, Decl(awaitedType.ts, 80, 1))
>T : Symbol(T, Decl(awaitedType.ts, 82, 18))
>x : Symbol(x, Decl(awaitedType.ts, 82, 33))
>T : Symbol(T, Decl(awaitedType.ts, 82, 18))
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 88, 9))
>x : Symbol(x, Decl(awaitedType.ts, 82, 33))
}
async function f9<T extends unknown>(x: T) {
>f9 : Symbol(f9, Decl(awaitedType.ts, 89, 1))
>T : Symbol(T, Decl(awaitedType.ts, 91, 18))
>x : Symbol(x, Decl(awaitedType.ts, 91, 37))
>T : Symbol(T, Decl(awaitedType.ts, 91, 18))
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 97, 9))
>x : Symbol(x, Decl(awaitedType.ts, 91, 37))
}
async function f10<T extends {}>(x: T) {
>f10 : Symbol(f10, Decl(awaitedType.ts, 98, 1))
>T : Symbol(T, Decl(awaitedType.ts, 100, 19))
>x : Symbol(x, Decl(awaitedType.ts, 100, 33))
>T : Symbol(T, Decl(awaitedType.ts, 100, 19))
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 106, 9))
>x : Symbol(x, Decl(awaitedType.ts, 100, 33))
}
async function f11<T extends { then(onfulfilled: (value: unknown) => void): void }>(x: T) {
>f11 : Symbol(f11, Decl(awaitedType.ts, 107, 1))
>T : Symbol(T, Decl(awaitedType.ts, 109, 19))
>then : Symbol(then, Decl(awaitedType.ts, 109, 30))
>onfulfilled : Symbol(onfulfilled, Decl(awaitedType.ts, 109, 36))
>value : Symbol(value, Decl(awaitedType.ts, 109, 50))
>x : Symbol(x, Decl(awaitedType.ts, 109, 84))
>T : Symbol(T, Decl(awaitedType.ts, 109, 19))
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 115, 9))
>x : Symbol(x, Decl(awaitedType.ts, 109, 84))
}
async function f12<T extends string | object>(x: T) {
>f12 : Symbol(f12, Decl(awaitedType.ts, 116, 1))
>T : Symbol(T, Decl(awaitedType.ts, 118, 19))
>x : Symbol(x, Decl(awaitedType.ts, 118, 46))
>T : Symbol(T, Decl(awaitedType.ts, 118, 19))
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 124, 9))
>x : Symbol(x, Decl(awaitedType.ts, 118, 46))
}
async function f13<T extends string>(x: T) {
>f13 : Symbol(f13, Decl(awaitedType.ts, 125, 1))
>T : Symbol(T, Decl(awaitedType.ts, 127, 19))
>x : Symbol(x, Decl(awaitedType.ts, 127, 37))
>T : Symbol(T, Decl(awaitedType.ts, 127, 19))
// NOTE: T belongs to the domain of primitive types
// y: T
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 131, 9))
>x : Symbol(x, Decl(awaitedType.ts, 127, 37))
}
async function f14<T extends { x: number }>(x: T) {
>f14 : Symbol(f14, Decl(awaitedType.ts, 132, 1))
>T : Symbol(T, Decl(awaitedType.ts, 134, 19))
>x : Symbol(x, Decl(awaitedType.ts, 134, 30))
>x : Symbol(x, Decl(awaitedType.ts, 134, 44))
>T : Symbol(T, Decl(awaitedType.ts, 134, 19))
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 138, 9))
>x : Symbol(x, Decl(awaitedType.ts, 134, 44))
}
async function f15<T extends { then: number }>(x: T) {
>f15 : Symbol(f15, Decl(awaitedType.ts, 139, 1))
>T : Symbol(T, Decl(awaitedType.ts, 141, 19))
>then : Symbol(then, Decl(awaitedType.ts, 141, 30))
>x : Symbol(x, Decl(awaitedType.ts, 141, 47))
>T : Symbol(T, Decl(awaitedType.ts, 141, 19))
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 145, 9))
>x : Symbol(x, Decl(awaitedType.ts, 141, 47))
}
async function f16<T extends number & { then(): void }>(x: T) {
>f16 : Symbol(f16, Decl(awaitedType.ts, 146, 1))
>T : Symbol(T, Decl(awaitedType.ts, 148, 19))
>then : Symbol(then, Decl(awaitedType.ts, 148, 39))
>x : Symbol(x, Decl(awaitedType.ts, 148, 56))
>T : Symbol(T, Decl(awaitedType.ts, 148, 19))
// NOTE: T belongs to the domain of primitive types (regardless of `then`)
// y: T
const y = await x;
>y : Symbol(y, Decl(awaitedType.ts, 152, 9))
>x : Symbol(x, Decl(awaitedType.ts, 148, 56))
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;
>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 153, 1))
>TActual : Symbol(TActual, Decl(awaitedType.ts, 157, 13))
>TExpected : Symbol(TExpected, Decl(awaitedType.ts, 157, 39))
>TExpected : Symbol(TExpected, Decl(awaitedType.ts, 157, 39))
>TActual : Symbol(TActual, Decl(awaitedType.ts, 157, 13))

View file

@ -0,0 +1,352 @@
=== tests/cases/compiler/awaitedType.ts ===
type T1 = Awaited<number>;
>T1 : number
type T2 = Awaited<Promise<number>>;
>T2 : number
type T3 = Awaited<number | Promise<number>>;
>T3 : number
type T4 = Awaited<number | Promise<string>>;
>T4 : T4
type T5 = Awaited<{ then: number }>;
>T5 : { then: number; }
>then : number
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
>T6 : never
>then : () => void
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
>T7 : never
>then : (x: number) => void
>x : number
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
>T8 : unknown
>then : (x: () => void) => void
>x : () => void
type T9 = Awaited<any>;
>T9 : any
type T10 = Awaited<never>;
>T10 : never
type T11 = Awaited<unknown>;
>T11 : unknown
type T12 = Awaited<Promise<Promise<number>>>;
>T12 : number
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
>T13 : string | number
>null : null
>null : null
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
>T14 : string | number
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
>T15 : string | number
>null : null
>null : null
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
>then : (cb: (value: BadPromise) => void) => void
>cb : (value: BadPromise) => void
>value : BadPromise
type T16 = Awaited<BadPromise>; // error
>T16 : any
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
>then : (cb: (value: BadPromise2) => void) => void
>cb : (value: BadPromise2) => void
>value : BadPromise2
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
>then : (cb: (value: BadPromise1) => void) => void
>cb : (value: BadPromise1) => void
>value : BadPromise1
type T17 = Awaited<BadPromise1>; // error
>T17 : any
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
>MaybePromise : MaybePromise<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
>MaybePromise : <T>(value: T) => MaybePromise<T>
>value : T
async function main() {
>main : () => Promise<void>
let aaa: number;
>aaa : number
let bbb: string;
>bbb : string
[
>[ aaa, bbb, ] = await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean]
>[ aaa, bbb, ] : [number, string]
aaa,
>aaa : number
bbb,
>bbb : string
] = await Promise.all([
>await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean]
>Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : Promise<[number, string, boolean]>
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise<true>]
MaybePromise(1),
>MaybePromise(1) : 1 | Promise<1> | PromiseLike<1>
>MaybePromise : <T>(value: T) => MaybePromise<T>
>1 : 1
MaybePromise('2'),
>MaybePromise('2') : "2" | Promise<"2"> | PromiseLike<"2">
>MaybePromise : <T>(value: T) => MaybePromise<T>
>'2' : "2"
MaybePromise(true),
>MaybePromise(true) : true | Promise<true> | PromiseLike<true>
>MaybePromise : <T>(value: T) => MaybePromise<T>
>true : true
])
}
// non-generic
async function f1(x: string) {
>f1 : (x: string) => Promise<void>
>x : string
// y: string
const y = await x;
>y : string
>await x : string
>x : string
}
async function f2(x: unknown) {
>f2 : (x: unknown) => Promise<void>
>x : unknown
// y: unknown
const y = await x;
>y : unknown
>await x : unknown
>x : unknown
}
async function f3(x: object) {
>f3 : (x: object) => Promise<void>
>x : object
// y: object
const y = await x;
>y : object
>await x : object
>x : object
}
async function f4(x: Promise<string>) {
>f4 : (x: Promise<string>) => Promise<void>
>x : Promise<string>
// y: string
const y = await x;
>y : string
>await x : string
>x : Promise<string>
}
async function f5(x: Promise<unknown>) {
>f5 : (x: Promise<unknown>) => Promise<void>
>x : Promise<unknown>
// y: unknown
const y = await x;
>y : unknown
>await x : unknown
>x : Promise<unknown>
}
async function f6(x: Promise<object>) {
>f6 : (x: Promise<object>) => Promise<void>
>x : Promise<object>
// y: object
const y = await x;
>y : object
>await x : object
>x : Promise<object>
}
// generic
async function f7<T>(x: T) {
>f7 : <T>(x: T) => Promise<void>
>x : T
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Awaited<T>
>await x : Awaited<T>
>x : T
}
async function f8<T extends any>(x: T) {
>f8 : <T extends unknown>(x: T) => Promise<void>
>x : T
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Awaited<T>
>await x : Awaited<T>
>x : T
}
async function f9<T extends unknown>(x: T) {
>f9 : <T extends unknown>(x: T) => Promise<void>
>x : T
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Awaited<T>
>await x : Awaited<T>
>x : T
}
async function f10<T extends {}>(x: T) {
>f10 : <T extends {}>(x: T) => Promise<void>
>x : T
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Awaited<T>
>await x : Awaited<T>
>x : T
}
async function f11<T extends { then(onfulfilled: (value: unknown) => void): void }>(x: T) {
>f11 : <T extends { then(onfulfilled: (value: unknown) => void): void; }>(x: T) => Promise<void>
>then : (onfulfilled: (value: unknown) => void) => void
>onfulfilled : (value: unknown) => void
>value : unknown
>x : T
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : unknown
>await x : unknown
>x : T
}
async function f12<T extends string | object>(x: T) {
>f12 : <T extends string | object>(x: T) => Promise<void>
>x : T
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
>y : Awaited<T>
>await x : Awaited<T>
>x : T
}
async function f13<T extends string>(x: T) {
>f13 : <T extends string>(x: T) => Promise<void>
>x : T
// NOTE: T belongs to the domain of primitive types
// y: T
const y = await x;
>y : T
>await x : T
>x : T
}
async function f14<T extends { x: number }>(x: T) {
>f14 : <T extends { x: number; }>(x: T) => Promise<void>
>x : number
>x : T
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
>y : T
>await x : T
>x : T
}
async function f15<T extends { then: number }>(x: T) {
>f15 : <T extends { then: number; }>(x: T) => Promise<void>
>then : number
>x : T
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
>y : T
>await x : T
>x : T
}
async function f16<T extends number & { then(): void }>(x: T) {
>f16 : <T extends number & { then(): void; }>(x: T) => Promise<void>
>then : () => void
>x : T
// NOTE: T belongs to the domain of primitive types (regardless of `then`)
// y: T
const y = await x;
>y : T
>await x : T
>x : T
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;
>_Expect : TActual

View file

@ -0,0 +1,52 @@
tests/cases/compiler/awaitedTypeStrictNull.ts(18,12): error TS2589: Type instantiation is excessively deep and possibly infinite.
tests/cases/compiler/awaitedTypeStrictNull.ts(22,12): error TS2589: Type instantiation is excessively deep and possibly infinite.
==== tests/cases/compiler/awaitedTypeStrictNull.ts (2 errors) ====
type T1 = Awaited<number>;
type T2 = Awaited<Promise<number>>;
type T3 = Awaited<number | Promise<number>>;
type T4 = Awaited<number | Promise<string>>;
type T5 = Awaited<{ then: number }>;
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
type T9 = Awaited<any>;
type T10 = Awaited<never>;
type T11 = Awaited<unknown>;
type T12 = Awaited<Promise<Promise<number>>>;
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
type T16 = Awaited<BadPromise>; // error
~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error
~~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
async function main() {
let aaa: number;
let bbb: string;
[
aaa,
bbb,
] = await Promise.all([
MaybePromise(1),
MaybePromise('2'),
MaybePromise(true),
])
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;

View file

@ -0,0 +1,58 @@
//// [awaitedTypeStrictNull.ts]
type T1 = Awaited<number>;
type T2 = Awaited<Promise<number>>;
type T3 = Awaited<number | Promise<number>>;
type T4 = Awaited<number | Promise<string>>;
type T5 = Awaited<{ then: number }>;
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
type T9 = Awaited<any>;
type T10 = Awaited<never>;
type T11 = Awaited<unknown>;
type T12 = Awaited<Promise<Promise<number>>>;
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
type T16 = Awaited<BadPromise>; // error
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
async function main() {
let aaa: number;
let bbb: string;
[
aaa,
bbb,
] = await Promise.all([
MaybePromise(1),
MaybePromise('2'),
MaybePromise(true),
])
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;
//// [awaitedTypeStrictNull.js]
async function main() {
let aaa;
let bbb;
[
aaa,
bbb,
] = await Promise.all([
MaybePromise(1),
MaybePromise('2'),
MaybePromise(true),
]);
}

View file

@ -0,0 +1,171 @@
=== tests/cases/compiler/awaitedTypeStrictNull.ts ===
type T1 = Awaited<number>;
>T1 : Symbol(T1, Decl(awaitedTypeStrictNull.ts, 0, 0))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
type T2 = Awaited<Promise<number>>;
>T2 : Symbol(T2, Decl(awaitedTypeStrictNull.ts, 0, 26))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T3 = Awaited<number | Promise<number>>;
>T3 : Symbol(T3, Decl(awaitedTypeStrictNull.ts, 1, 35))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T4 = Awaited<number | Promise<string>>;
>T4 : Symbol(T4, Decl(awaitedTypeStrictNull.ts, 2, 44))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T5 = Awaited<{ then: number }>;
>T5 : Symbol(T5, Decl(awaitedTypeStrictNull.ts, 3, 44))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 4, 19))
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
>T6 : Symbol(T6, Decl(awaitedTypeStrictNull.ts, 4, 36))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 5, 19))
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
>T7 : Symbol(T7, Decl(awaitedTypeStrictNull.ts, 5, 36))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 6, 19))
>x : Symbol(x, Decl(awaitedTypeStrictNull.ts, 6, 25))
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
>T8 : Symbol(T8, Decl(awaitedTypeStrictNull.ts, 6, 45))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 7, 19))
>x : Symbol(x, Decl(awaitedTypeStrictNull.ts, 7, 25))
type T9 = Awaited<any>;
>T9 : Symbol(T9, Decl(awaitedTypeStrictNull.ts, 7, 49))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
type T10 = Awaited<never>;
>T10 : Symbol(T10, Decl(awaitedTypeStrictNull.ts, 8, 23))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
type T11 = Awaited<unknown>;
>T11 : Symbol(T11, Decl(awaitedTypeStrictNull.ts, 9, 26))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
type T12 = Awaited<Promise<Promise<number>>>;
>T12 : Symbol(T12, Decl(awaitedTypeStrictNull.ts, 10, 28))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
>T13 : Symbol(T13, Decl(awaitedTypeStrictNull.ts, 11, 45))
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 38, 1))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
>T14 : Symbol(T14, Decl(awaitedTypeStrictNull.ts, 12, 107))
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 38, 1))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
>T15 : Symbol(T15, Decl(awaitedTypeStrictNull.ts, 13, 117))
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 38, 1))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
>BadPromise : Symbol(BadPromise, Decl(awaitedTypeStrictNull.ts, 14, 131))
>then : Symbol(BadPromise.then, Decl(awaitedTypeStrictNull.ts, 16, 22))
>cb : Symbol(cb, Decl(awaitedTypeStrictNull.ts, 16, 28))
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 16, 33))
>BadPromise : Symbol(BadPromise, Decl(awaitedTypeStrictNull.ts, 14, 131))
type T16 = Awaited<BadPromise>; // error
>T16 : Symbol(T16, Decl(awaitedTypeStrictNull.ts, 16, 69))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>BadPromise : Symbol(BadPromise, Decl(awaitedTypeStrictNull.ts, 14, 131))
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
>BadPromise1 : Symbol(BadPromise1, Decl(awaitedTypeStrictNull.ts, 17, 31))
>then : Symbol(BadPromise1.then, Decl(awaitedTypeStrictNull.ts, 19, 23))
>cb : Symbol(cb, Decl(awaitedTypeStrictNull.ts, 19, 29))
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 19, 34))
>BadPromise2 : Symbol(BadPromise2, Decl(awaitedTypeStrictNull.ts, 19, 71))
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
>BadPromise2 : Symbol(BadPromise2, Decl(awaitedTypeStrictNull.ts, 19, 71))
>then : Symbol(BadPromise2.then, Decl(awaitedTypeStrictNull.ts, 20, 23))
>cb : Symbol(cb, Decl(awaitedTypeStrictNull.ts, 20, 29))
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 20, 34))
>BadPromise1 : Symbol(BadPromise1, Decl(awaitedTypeStrictNull.ts, 17, 31))
type T17 = Awaited<BadPromise1>; // error
>T17 : Symbol(T17, Decl(awaitedTypeStrictNull.ts, 20, 71))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>BadPromise1 : Symbol(BadPromise1, Decl(awaitedTypeStrictNull.ts, 17, 31))
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
declare function MaybePromise<T>(value: T): MaybePromise<T>;
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30))
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 25, 33))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30))
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30))
async function main() {
>main : Symbol(main, Decl(awaitedTypeStrictNull.ts, 25, 60))
let aaa: number;
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 28, 7))
let bbb: string;
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7))
[
aaa,
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 28, 7))
bbb,
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7))
] = await Promise.all([
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
MaybePromise(1),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
MaybePromise('2'),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
MaybePromise(true),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
])
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 38, 1))
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 41, 13))
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 41, 39))
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 41, 39))
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 41, 13))

View file

@ -0,0 +1,134 @@
=== tests/cases/compiler/awaitedTypeStrictNull.ts ===
type T1 = Awaited<number>;
>T1 : number
type T2 = Awaited<Promise<number>>;
>T2 : number
type T3 = Awaited<number | Promise<number>>;
>T3 : number
type T4 = Awaited<number | Promise<string>>;
>T4 : T4
type T5 = Awaited<{ then: number }>;
>T5 : { then: number; }
>then : number
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
>T6 : never
>then : () => void
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
>T7 : never
>then : (x: number) => void
>x : number
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
>T8 : unknown
>then : (x: () => void) => void
>x : () => void
type T9 = Awaited<any>;
>T9 : any
type T10 = Awaited<never>;
>T10 : never
type T11 = Awaited<unknown>;
>T11 : unknown
type T12 = Awaited<Promise<Promise<number>>>;
>T12 : number
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
>T13 : string | number | null
>null : null
>null : null
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
>T14 : string | number | undefined
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
>T15 : string | number | null | undefined
>null : null
>null : null
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
>then : (cb: (value: BadPromise) => void) => void
>cb : (value: BadPromise) => void
>value : BadPromise
type T16 = Awaited<BadPromise>; // error
>T16 : any
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
>then : (cb: (value: BadPromise2) => void) => void
>cb : (value: BadPromise2) => void
>value : BadPromise2
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
>then : (cb: (value: BadPromise1) => void) => void
>cb : (value: BadPromise1) => void
>value : BadPromise1
type T17 = Awaited<BadPromise1>; // error
>T17 : any
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
>MaybePromise : MaybePromise<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
>MaybePromise : <T>(value: T) => MaybePromise<T>
>value : T
async function main() {
>main : () => Promise<void>
let aaa: number;
>aaa : number
let bbb: string;
>bbb : string
[
>[ aaa, bbb, ] = await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean]
>[ aaa, bbb, ] : [number, string]
aaa,
>aaa : number
bbb,
>bbb : string
] = await Promise.all([
>await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean]
>Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : Promise<[number, string, boolean]>
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise<true>]
MaybePromise(1),
>MaybePromise(1) : 1 | Promise<1> | PromiseLike<1>
>MaybePromise : <T>(value: T) => MaybePromise<T>
>1 : 1
MaybePromise('2'),
>MaybePromise('2') : "2" | Promise<"2"> | PromiseLike<"2">
>MaybePromise : <T>(value: T) => MaybePromise<T>
>'2' : "2"
MaybePromise(true),
>MaybePromise(true) : true | Promise<true> | PromiseLike<true>
>MaybePromise : <T>(value: T) => MaybePromise<T>
>true : true
])
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;
>_Expect : TActual

View file

@ -33,9 +33,9 @@ async function countEverything(): Promise<number> {
const [resultA, resultB] = await Promise.all([
>resultA : Symbol(resultA, Decl(correctOrderOfPromiseMethod.ts, 13, 11))
>resultB : Symbol(resultB, Decl(correctOrderOfPromiseMethod.ts, 13, 19))
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
providerA(),
>providerA : Symbol(providerA, Decl(correctOrderOfPromiseMethod.ts, 10, 9))
@ -75,8 +75,8 @@ async function countEverything(): Promise<number> {
const expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]);
>expected : Symbol(expected, Decl(correctOrderOfPromiseMethod.ts, 28, 5))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>undefined : Symbol(undefined)

View file

@ -30,9 +30,9 @@ async function countEverything(): Promise<number> {
>resultB : B[]
>await Promise.all([ providerA(), providerB(), ]) : [A[], B[]]
>Promise.all([ providerA(), providerB(), ]) : Promise<[A[], B[]]>
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>; }
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>; }
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[ providerA(), providerB(), ] : [Promise<A[]>, Promise<B[]>]
providerA(),
@ -76,9 +76,9 @@ async function countEverything(): Promise<number> {
const expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]);
>expected : Promise<["a", "b", "c"]>
>Promise.all(undefined as readonly ["a", "b", "c"]) : Promise<["a", "b", "c"]>
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>; }
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>; }
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>undefined as readonly ["a", "b", "c"] : readonly ["a", "b", "c"]
>undefined : undefined

View file

@ -1,5 +1,5 @@
tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts(3,3): error TS2322: Type 'T | Yadda' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'T | Yadda'.
tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts(3,3): error TS2322: Type 'Yadda | Awaited<T>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'Yadda | Awaited<T>'.
==== tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts (1 errors) ====
@ -7,8 +7,8 @@ tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts(3,3): error
let yaddable = await getXOrYadda(x);
return yaddable;
~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'T | Yadda' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'T | Yadda'.
!!! error TS2322: Type 'Yadda | Awaited<T>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Yadda | Awaited<T>'.
}
interface Yadda {

View file

@ -4,14 +4,14 @@ async function foo<T>(x: T): Promise<T> {
>x : T
let yaddable = await getXOrYadda(x);
>yaddable : T | Yadda
>await getXOrYadda(x) : T | Yadda
>yaddable : Yadda | Awaited<T>
>await getXOrYadda(x) : Yadda | Awaited<T>
>getXOrYadda(x) : T | Yadda
>getXOrYadda : <T>(x: T) => T | Yadda
>x : T
return yaddable;
>yaddable : T | Yadda
>yaddable : Yadda | Awaited<T>
}
interface Yadda {

View file

@ -4,7 +4,7 @@ async function f<T>(source: Iterable<T> | AsyncIterable<T>) {
>source : Iterable<T> | AsyncIterable<T>
for await (const x of source) {
>x : T
>x : Awaited<T>
>source : Iterable<T> | AsyncIterable<T>
}
}

View file

@ -381,9 +381,9 @@ const f1: F = () => {
>F : Symbol(F, Decl(inferFromGenericFunctionReturnTypes3.ts, 153, 2))
return Promise.all([
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
{
name: "David Gomes",
>name : Symbol(name, Decl(inferFromGenericFunctionReturnTypes3.ts, 159, 9))

View file

@ -409,14 +409,14 @@ type F = () => Promise<Array<Player>>;
const f1: F = () => {
>f1 : F
>() => { return Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]);} : () => Promise<[{ name: string; age: number; position: "GOALKEEPER"; }, { name: string; age: number; position: "STRIKER"; }]>
>() => { return Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]);} : () => Promise<({ name: string; age: number; position: "GOALKEEPER"; } | { name: string; age: number; position: "STRIKER"; })[]>
return Promise.all([
>Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]) : Promise<[{ name: string; age: number; position: "GOALKEEPER"; }, { name: string; age: number; position: "STRIKER"; }]>
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>; }
>Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]) : Promise<({ name: string; age: number; position: "GOALKEEPER"; } | { name: string; age: number; position: "STRIKER"; })[]>
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends [] | readonly unknown[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>; }
>[ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ] : [{ name: string; age: number; position: "GOALKEEPER"; }, { name: string; age: number; position: "STRIKER"; }]
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends [] | readonly unknown[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ] : ({ name: string; age: number; position: "GOALKEEPER"; } | { name: string; age: number; position: "STRIKER"; })[]
{
>{ name: "David Gomes", age: 23, position: "GOALKEEPER", } : { name: string; age: number; position: "GOALKEEPER"; }

View file

@ -61,9 +61,9 @@ export class BrokenClass {
return Promise.all(result.map(populateItems))
>Promise.all(result.map(populateItems)) .then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>result.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
>result : Symbol(result, Decl(file1.ts, 10, 7))
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))

View file

@ -76,9 +76,9 @@ export class BrokenClass {
>Promise.all(result.map(populateItems)) .then((orders: Array<MyModule.MyModel>) => { resolve(orders); }) : Promise<void>
>Promise.all(result.map(populateItems)) .then : <TResult1 = unknown[], TResult2 = never>(onfulfilled?: (value: unknown[]) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
>Promise.all(result.map(populateItems)) : Promise<unknown[]>
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>; }
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>; }
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>result.map(populateItems) : Promise<unknown>[]
>result.map : <U>(callbackfn: (value: MyModule.MyModel, index: number, array: MyModule.MyModel[]) => U, thisArg?: any) => U[]
>result : MyModule.MyModel[]

View file

@ -58,8 +58,8 @@ let y21 = nonpartial(x21);
declare let x22: { a: number | undefined, b?: string[] };
let y22 = nonpartial(x22);
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
type Awaitified<T> = { [P in keyof T]: Awaited<T[P]> };
type __Awaited<T> = T extends PromiseLike<infer U> ? U : T;
type Awaitified<T> = { [P in keyof T]: __Awaited<T[P]> };
declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>;
@ -189,9 +189,9 @@ declare let y22: {
a: number;
b: string[];
};
declare type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
declare type __Awaited<T> = T extends PromiseLike<infer U> ? U : T;
declare type Awaitified<T> = {
[P in keyof T]: Awaited<T[P]>;
[P in keyof T]: __Awaited<T[P]>;
};
declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>;
declare function f1(a: number, b: Promise<number>, c: string[], d: Promise<string[]>): void;

View file

@ -214,31 +214,31 @@ let y22 = nonpartial(x22);
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 46, 24))
>x22 : Symbol(x22, Decl(mappedTypesArraysTuples.ts, 56, 11))
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
>Awaited : Symbol(Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13))
type __Awaited<T> = T extends PromiseLike<infer U> ? U : T;
>__Awaited : Symbol(__Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 15))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 15))
>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --))
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 45))
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 45))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13))
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 47))
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 47))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 15))
type Awaitified<T> = { [P in keyof T]: Awaited<T[P]> };
>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 57))
type Awaitified<T> = { [P in keyof T]: __Awaited<T[P]> };
>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 59))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16))
>P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 60, 24))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16))
>Awaited : Symbol(Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26))
>__Awaited : Symbol(__Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16))
>P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 60, 24))
declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>;
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21))
>values : Symbol(values, Decl(mappedTypesArraysTuples.ts, 62, 38))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --))
>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 57))
>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 59))
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21))
function f1(a: number, b: Promise<number>, c: string[], d: Promise<string[]>) {
@ -252,25 +252,25 @@ function f1(a: number, b: Promise<number>, c: string[], d: Promise<string[]>) {
let x1 = all(a);
>x1 : Symbol(x1, Decl(mappedTypesArraysTuples.ts, 65, 7))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57))
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
let x2 = all(a, b);
>x2 : Symbol(x2, Decl(mappedTypesArraysTuples.ts, 66, 7))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57))
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22))
let x3 = all(a, b, c);
>x3 : Symbol(x3, Decl(mappedTypesArraysTuples.ts, 67, 7))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57))
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22))
>c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 64, 42))
let x4 = all(a, b, c, d);
>x4 : Symbol(x4, Decl(mappedTypesArraysTuples.ts, 68, 7))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57))
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22))
>c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 64, 42))

View file

@ -152,10 +152,10 @@ let y22 = nonpartial(x22);
>nonpartial : <T>(x: Partial<T>) => T
>x22 : { a: number | undefined; b?: string[] | undefined; }
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
>Awaited : Awaited<T>
type __Awaited<T> = T extends PromiseLike<infer U> ? U : T;
>__Awaited : __Awaited<T>
type Awaitified<T> = { [P in keyof T]: Awaited<T[P]> };
type Awaitified<T> = { [P in keyof T]: __Awaited<T[P]> };
>Awaitified : Awaitified<T>
declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>;

View file

@ -1,10 +1,10 @@
tests/cases/compiler/recursiveConditionalTypes.ts(16,11): error TS2589: Type instantiation is excessively deep and possibly infinite.
tests/cases/compiler/recursiveConditionalTypes.ts(20,5): error TS2322: Type 'Awaited<T>' is not assignable to type 'Awaited<U>'.
tests/cases/compiler/recursiveConditionalTypes.ts(20,5): error TS2322: Type '__Awaited<T>' is not assignable to type '__Awaited<U>'.
Type 'T' is not assignable to type 'U'.
'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
tests/cases/compiler/recursiveConditionalTypes.ts(21,5): error TS2322: Type 'T' is not assignable to type 'Awaited<T>'.
tests/cases/compiler/recursiveConditionalTypes.ts(22,5): error TS2322: Type 'Awaited<T>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'Awaited<T>'.
tests/cases/compiler/recursiveConditionalTypes.ts(21,5): error TS2322: Type 'T' is not assignable to type '__Awaited<T>'.
tests/cases/compiler/recursiveConditionalTypes.ts(22,5): error TS2322: Type '__Awaited<T>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to '__Awaited<T>'.
tests/cases/compiler/recursiveConditionalTypes.ts(35,11): error TS2589: Type instantiation is excessively deep and possibly infinite.
tests/cases/compiler/recursiveConditionalTypes.ts(47,12): error TS2589: Type instantiation is excessively deep and possibly infinite.
tests/cases/compiler/recursiveConditionalTypes.ts(50,5): error TS2322: Type 'TupleOf<number, M>' is not assignable to type 'TupleOf<number, N>'.
@ -28,9 +28,9 @@ tests/cases/compiler/recursiveConditionalTypes.ts(117,9): error TS2345: Argument
==== tests/cases/compiler/recursiveConditionalTypes.ts (9 errors) ====
// Awaiting promises
type Awaited<T> =
type __Awaited<T> =
T extends null | undefined ? T :
T extends PromiseLike<infer U> ? Awaited<U> :
T extends PromiseLike<infer U> ? __Awaited<U> :
T;
type MyPromise<T> = {
@ -39,26 +39,26 @@ tests/cases/compiler/recursiveConditionalTypes.ts(117,9): error TS2345: Argument
type InfinitePromise<T> = Promise<InfinitePromise<T>>;
type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
type P1 = Awaited<any>;
type P2 = Awaited<InfinitePromise<number>>; // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type P0 = __Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
type P1 = __Awaited<any>;
type P2 = __Awaited<InfinitePromise<number>>; // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>) {
function f11<T, U extends T>(tx: T, ta: __Awaited<T>, ux: U, ua: __Awaited<U>) {
ta = ua;
ua = ta; // Error
~~
!!! error TS2322: Type 'Awaited<T>' is not assignable to type 'Awaited<U>'.
!!! error TS2322: Type '__Awaited<T>' is not assignable to type '__Awaited<U>'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
ta = tx; // Error
~~
!!! error TS2322: Type 'T' is not assignable to type 'Awaited<T>'.
!!! error TS2322: Type 'T' is not assignable to type '__Awaited<T>'.
tx = ta; // Error
~~
!!! error TS2322: Type 'Awaited<T>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Awaited<T>'.
!!! error TS2322: Type '__Awaited<T>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to '__Awaited<T>'.
}
// Flattening arrays

View file

@ -1,9 +1,9 @@
//// [recursiveConditionalTypes.ts]
// Awaiting promises
type Awaited<T> =
type __Awaited<T> =
T extends null | undefined ? T :
T extends PromiseLike<infer U> ? Awaited<U> :
T extends PromiseLike<infer U> ? __Awaited<U> :
T;
type MyPromise<T> = {
@ -12,11 +12,11 @@ type MyPromise<T> = {
type InfinitePromise<T> = Promise<InfinitePromise<T>>;
type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
type P1 = Awaited<any>;
type P2 = Awaited<InfinitePromise<number>>; // Error
type P0 = __Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
type P1 = __Awaited<any>;
type P2 = __Awaited<InfinitePromise<number>>; // Error
function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>) {
function f11<T, U extends T>(tx: T, ta: __Awaited<T>, ux: U, ua: __Awaited<U>) {
ta = ua;
ua = ta; // Error
ta = tx; // Error
@ -172,15 +172,15 @@ function f21(x, y) {
//// [recursiveConditionalTypes.d.ts]
declare type Awaited<T> = T extends null | undefined ? T : T extends PromiseLike<infer U> ? Awaited<U> : T;
declare type __Awaited<T> = T extends null | undefined ? T : T extends PromiseLike<infer U> ? __Awaited<U> : T;
declare type MyPromise<T> = {
then<U>(f: ((value: T) => U | PromiseLike<U>) | null | undefined): MyPromise<U>;
};
declare type InfinitePromise<T> = Promise<InfinitePromise<T>>;
declare type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
declare type P1 = Awaited<any>;
declare type P2 = Awaited<InfinitePromise<number>>;
declare function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>): void;
declare type P0 = __Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
declare type P1 = __Awaited<any>;
declare type P2 = __Awaited<InfinitePromise<number>>;
declare function f11<T, U extends T>(tx: T, ta: __Awaited<T>, ux: U, ua: __Awaited<U>): void;
declare type Flatten<T extends readonly unknown[]> = T extends unknown[] ? _Flatten<T>[] : readonly _Flatten<T>[];
declare type _Flatten<T> = T extends readonly (infer U)[] ? _Flatten<U> : T;
declare type InfiniteArray<T> = InfiniteArray<T>[];

View file

@ -1,23 +1,23 @@
=== tests/cases/compiler/recursiveConditionalTypes.ts ===
// Awaiting promises
type Awaited<T> =
>Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13))
type __Awaited<T> =
>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15))
T extends null | undefined ? T :
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15))
T extends PromiseLike<infer U> ? Awaited<U> :
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13))
T extends PromiseLike<infer U> ? __Awaited<U> :
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15))
>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --))
>U : Symbol(U, Decl(recursiveConditionalTypes.ts, 4, 31))
>Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>U : Symbol(U, Decl(recursiveConditionalTypes.ts, 4, 31))
T;
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15))
type MyPromise<T> = {
>MyPromise : Symbol(MyPromise, Decl(recursiveConditionalTypes.ts, 5, 6))
@ -43,44 +43,44 @@ type InfinitePromise<T> = Promise<InfinitePromise<T>>;
>InfinitePromise : Symbol(InfinitePromise, Decl(recursiveConditionalTypes.ts, 9, 1))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 11, 21))
type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
type P0 = __Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
>P0 : Symbol(P0, Decl(recursiveConditionalTypes.ts, 11, 54))
>Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>MyPromise : Symbol(MyPromise, Decl(recursiveConditionalTypes.ts, 5, 6))
type P1 = Awaited<any>;
>P1 : Symbol(P1, Decl(recursiveConditionalTypes.ts, 13, 83))
>Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
type P1 = __Awaited<any>;
>P1 : Symbol(P1, Decl(recursiveConditionalTypes.ts, 13, 85))
>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
type P2 = Awaited<InfinitePromise<number>>; // Error
>P2 : Symbol(P2, Decl(recursiveConditionalTypes.ts, 14, 23))
>Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
type P2 = __Awaited<InfinitePromise<number>>; // Error
>P2 : Symbol(P2, Decl(recursiveConditionalTypes.ts, 14, 25))
>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>InfinitePromise : Symbol(InfinitePromise, Decl(recursiveConditionalTypes.ts, 9, 1))
function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>) {
>f11 : Symbol(f11, Decl(recursiveConditionalTypes.ts, 15, 43))
function f11<T, U extends T>(tx: T, ta: __Awaited<T>, ux: U, ua: __Awaited<U>) {
>f11 : Symbol(f11, Decl(recursiveConditionalTypes.ts, 15, 45))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 17, 13))
>U : Symbol(U, Decl(recursiveConditionalTypes.ts, 17, 15))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 17, 13))
>tx : Symbol(tx, Decl(recursiveConditionalTypes.ts, 17, 29))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 17, 13))
>ta : Symbol(ta, Decl(recursiveConditionalTypes.ts, 17, 35))
>Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 17, 13))
>ux : Symbol(ux, Decl(recursiveConditionalTypes.ts, 17, 51))
>ux : Symbol(ux, Decl(recursiveConditionalTypes.ts, 17, 53))
>U : Symbol(U, Decl(recursiveConditionalTypes.ts, 17, 15))
>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 58))
>Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 60))
>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0))
>U : Symbol(U, Decl(recursiveConditionalTypes.ts, 17, 15))
ta = ua;
>ta : Symbol(ta, Decl(recursiveConditionalTypes.ts, 17, 35))
>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 58))
>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 60))
ua = ta; // Error
>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 58))
>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 60))
>ta : Symbol(ta, Decl(recursiveConditionalTypes.ts, 17, 35))
ta = tx; // Error

View file

@ -1,13 +1,13 @@
=== tests/cases/compiler/recursiveConditionalTypes.ts ===
// Awaiting promises
type Awaited<T> =
>Awaited : Awaited<T>
type __Awaited<T> =
>__Awaited : __Awaited<T>
T extends null | undefined ? T :
>null : null
T extends PromiseLike<infer U> ? Awaited<U> :
T extends PromiseLike<infer U> ? __Awaited<U> :
T;
type MyPromise<T> = {
@ -23,42 +23,42 @@ type MyPromise<T> = {
type InfinitePromise<T> = Promise<InfinitePromise<T>>;
>InfinitePromise : InfinitePromise<T>
type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
type P0 = __Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
>P0 : string | number | null | undefined
>null : null
type P1 = Awaited<any>;
type P1 = __Awaited<any>;
>P1 : any
type P2 = Awaited<InfinitePromise<number>>; // Error
type P2 = __Awaited<InfinitePromise<number>>; // Error
>P2 : any
function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>) {
>f11 : <T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>) => void
function f11<T, U extends T>(tx: T, ta: __Awaited<T>, ux: U, ua: __Awaited<U>) {
>f11 : <T, U extends T>(tx: T, ta: __Awaited<T>, ux: U, ua: __Awaited<U>) => void
>tx : T
>ta : Awaited<T>
>ta : __Awaited<T>
>ux : U
>ua : Awaited<U>
>ua : __Awaited<U>
ta = ua;
>ta = ua : Awaited<U>
>ta : Awaited<T>
>ua : Awaited<U>
>ta = ua : __Awaited<U>
>ta : __Awaited<T>
>ua : __Awaited<U>
ua = ta; // Error
>ua = ta : Awaited<T>
>ua : Awaited<U>
>ta : Awaited<T>
>ua = ta : __Awaited<T>
>ua : __Awaited<U>
>ta : __Awaited<T>
ta = tx; // Error
>ta = tx : T
>ta : Awaited<T>
>ta : __Awaited<T>
>tx : T
tx = ta; // Error
>tx = ta : Awaited<T>
>tx = ta : __Awaited<T>
>tx : T
>ta : Awaited<T>
>ta : __Awaited<T>
}
// Flattening arrays

View file

@ -0,0 +1,161 @@
// @target: esnext
// @strictNullChecks: false
type T1 = Awaited<number>;
type T2 = Awaited<Promise<number>>;
type T3 = Awaited<number | Promise<number>>;
type T4 = Awaited<number | Promise<string>>;
type T5 = Awaited<{ then: number }>;
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
type T9 = Awaited<any>;
type T10 = Awaited<never>;
type T11 = Awaited<unknown>;
type T12 = Awaited<Promise<Promise<number>>>;
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
type T16 = Awaited<BadPromise>; // error
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
async function main() {
let aaa: number;
let bbb: string;
[
aaa,
bbb,
] = await Promise.all([
MaybePromise(1),
MaybePromise('2'),
MaybePromise(true),
])
}
// non-generic
async function f1(x: string) {
// y: string
const y = await x;
}
async function f2(x: unknown) {
// y: unknown
const y = await x;
}
async function f3(x: object) {
// y: object
const y = await x;
}
async function f4(x: Promise<string>) {
// y: string
const y = await x;
}
async function f5(x: Promise<unknown>) {
// y: unknown
const y = await x;
}
async function f6(x: Promise<object>) {
// y: object
const y = await x;
}
// generic
async function f7<T>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f8<T extends any>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f9<T extends unknown>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f10<T extends {}>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f11<T extends { then(onfulfilled: (value: unknown) => void): void }>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f12<T extends string | object>(x: T) {
// NOTE: T does not belong solely to the domain of primitive types and either does
// not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`,
// or it has a non-primitive base constraint with a callable `then`.
// y: Awaited<T>
const y = await x;
}
async function f13<T extends string>(x: T) {
// NOTE: T belongs to the domain of primitive types
// y: T
const y = await x;
}
async function f14<T extends { x: number }>(x: T) {
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
}
async function f15<T extends { then: number }>(x: T) {
// NOTE: T has a non-primitive base constraint without a callable `then`.
// y: T
const y = await x;
}
async function f16<T extends number & { then(): void }>(x: T) {
// NOTE: T belongs to the domain of primitive types (regardless of `then`)
// y: T
const y = await x;
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;

View file

@ -0,0 +1,45 @@
// @target: esnext
// @strictNullChecks: true
type T1 = Awaited<number>;
type T2 = Awaited<Promise<number>>;
type T3 = Awaited<number | Promise<number>>;
type T4 = Awaited<number | Promise<string>>;
type T5 = Awaited<{ then: number }>;
type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable")
type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable")
type T8 = Awaited<{ then(x: () => void): void }>; // unknown
type T9 = Awaited<any>;
type T10 = Awaited<never>;
type T11 = Awaited<unknown>;
type T12 = Awaited<Promise<Promise<number>>>;
type T13 = _Expect<Awaited<Promise<Promise<number>> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful
type T14 = _Expect<Awaited<Promise<Promise<number>> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful
type T15 = _Expect<Awaited<Promise<Promise<number>> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful
interface BadPromise { then(cb: (value: BadPromise) => void): void; }
type T16 = Awaited<BadPromise>; // error
interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error
// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
async function main() {
let aaa: number;
let bbb: string;
[
aaa,
bbb,
] = await Promise.all([
MaybePromise(1),
MaybePromise('2'),
MaybePromise(true),
])
}
// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;

View file

@ -4,9 +4,9 @@
// Awaiting promises
type Awaited<T> =
type __Awaited<T> =
T extends null | undefined ? T :
T extends PromiseLike<infer U> ? Awaited<U> :
T extends PromiseLike<infer U> ? __Awaited<U> :
T;
type MyPromise<T> = {
@ -15,11 +15,11 @@ type MyPromise<T> = {
type InfinitePromise<T> = Promise<InfinitePromise<T>>;
type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
type P1 = Awaited<any>;
type P2 = Awaited<InfinitePromise<number>>; // Error
type P0 = __Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
type P1 = __Awaited<any>;
type P2 = __Awaited<InfinitePromise<number>>; // Error
function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>) {
function f11<T, U extends T>(tx: T, ta: __Awaited<T>, ux: U, ua: __Awaited<U>) {
ta = ua;
ua = ta; // Error
ta = tx; // Error

View file

@ -60,8 +60,8 @@ let y21 = nonpartial(x21);
declare let x22: { a: number | undefined, b?: string[] };
let y22 = nonpartial(x22);
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
type Awaitified<T> = { [P in keyof T]: Awaited<T[P]> };
type __Awaited<T> = T extends PromiseLike<infer U> ? U : T;
type Awaitified<T> = { [P in keyof T]: __Awaited<T[P]> };
declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>;