From ea521d45e92ab45fd168aa8ea97bd6f3b8952307 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 9 Sep 2021 18:23:17 -0700 Subject: [PATCH] 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 with 'await' * Clean up overloads * Further restrict 'Awaited' auto-wrapping for 'await' --- src/compiler/checker.ts | 255 +++++++---- src/harness/fourslashInterfaceImpl.ts | 1 + src/lib/es2015.iterable.d.ts | 12 +- src/lib/es2015.promise.d.ts | 76 +--- src/lib/es2020.promise.d.ts | 5 +- src/lib/es2021.promise.d.ts | 9 +- src/lib/es5.d.ts | 13 + .../asyncArrowFunction9_es2017.errors.txt | 2 +- .../asyncArrowFunction9_es5.errors.txt | 2 +- .../asyncArrowFunction9_es6.errors.txt | 2 +- .../reference/awaitedType.errors.txt | 168 ++++++++ tests/baselines/reference/awaitedType.js | 262 ++++++++++++ tests/baselines/reference/awaitedType.symbols | 396 ++++++++++++++++++ tests/baselines/reference/awaitedType.types | 352 ++++++++++++++++ .../awaitedTypeStrictNull.errors.txt | 52 +++ .../reference/awaitedTypeStrictNull.js | 58 +++ .../reference/awaitedTypeStrictNull.symbols | 171 ++++++++ .../reference/awaitedTypeStrictNull.types | 134 ++++++ .../correctOrderOfPromiseMethod.symbols | 8 +- .../correctOrderOfPromiseMethod.types | 8 +- ...teAssignabilityToTypeParameters.errors.txt | 8 +- ...aborateAssignabilityToTypeParameters.types | 6 +- .../reference/forAwaitForUnion.types | 2 +- ...ferFromGenericFunctionReturnTypes3.symbols | 4 +- ...inferFromGenericFunctionReturnTypes3.types | 10 +- .../reference/inferenceLimit.symbols | 4 +- .../baselines/reference/inferenceLimit.types | 4 +- .../reference/mappedTypesArraysTuples.js | 8 +- .../reference/mappedTypesArraysTuples.symbols | 32 +- .../reference/mappedTypesArraysTuples.types | 6 +- .../recursiveConditionalTypes.errors.txt | 30 +- .../reference/recursiveConditionalTypes.js | 22 +- .../recursiveConditionalTypes.symbols | 50 +-- .../reference/recursiveConditionalTypes.types | 38 +- tests/cases/compiler/awaitedType.ts | 161 +++++++ tests/cases/compiler/awaitedTypeStrictNull.ts | 45 ++ .../compiler/recursiveConditionalTypes.ts | 12 +- .../types/mapped/mappedTypesArraysTuples.ts | 4 +- 38 files changed, 2142 insertions(+), 290 deletions(-) create mode 100644 tests/baselines/reference/awaitedType.errors.txt create mode 100644 tests/baselines/reference/awaitedType.js create mode 100644 tests/baselines/reference/awaitedType.symbols create mode 100644 tests/baselines/reference/awaitedType.types create mode 100644 tests/baselines/reference/awaitedTypeStrictNull.errors.txt create mode 100644 tests/baselines/reference/awaitedTypeStrictNull.js create mode 100644 tests/baselines/reference/awaitedTypeStrictNull.symbols create mode 100644 tests/baselines/reference/awaitedTypeStrictNull.types create mode 100644 tests/cases/compiler/awaitedType.ts create mode 100644 tests/cases/compiler/awaitedTypeStrictNull.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c6a9e7e7ba..30d9ad9021 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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(); // 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` 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`, 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` based on the following conditions: + // - `T` is not already an `Awaited`, 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`, just return it. This helps to avoid `Awaited>` in higher-order. + if (isAwaitedTypeInstantiation(type)) { + return type; + } + + // Only instantiate `Awaited` if `T` contains possibly non-primitive types. + if (isGenericObjectType(type)) { + const baseConstraint = getBaseConstraintOfType(type); + // Only instantiate `Awaited` 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` doesn't exist + const awaitedSymbol = getGlobalAwaitedSymbol(/*reportErrors*/ true); + if (awaitedSymbol) { + // Unwrap unions that may contain `Awaited`, otherwise its possible to manufacture an `Awaited | U>` where + // an `Awaited` 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`, just return it. This avoids `Awaited>` in higher-order + if (isAwaitedTypeInstantiation(type)) { + return type; + } + + // If we've already cached an awaited type, return a possible `Awaited` 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 . 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`. + 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` or `AsyncGenerator` 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; } diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index c7a2f1d0f0..f1a92013fb 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1095,6 +1095,7 @@ namespace FourSlashInterface { typeEntry("PromiseConstructorLike"), interfaceEntry("PromiseLike"), interfaceEntry("Promise"), + typeEntry("Awaited"), interfaceEntry("ArrayLike"), typeEntry("Partial"), typeEntry("Required"), diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index f8805a30eb..20b6920e0d 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -203,7 +203,7 @@ interface PromiseConstructor { * @param values An iterable of Promises. * @returns A new Promise. */ - all(values: Iterable>): Promise; + all(values: Iterable>): Promise[]>; /** * 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(values: Iterable): Promise ? 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(values: Iterable>): Promise; + race(values: Iterable>): Promise>; } interface String { diff --git a/src/lib/es2015.promise.d.ts b/src/lib/es2015.promise.d.ts index 7d31dc9668..ac8f36de4b 100644 --- a/src/lib/es2015.promise.d.ts +++ b/src/lib/es2015.promise.d.ts @@ -18,79 +18,7 @@ interface PromiseConstructor { * @param values An array of Promises. * @returns A new Promise. */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): 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(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): 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(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): 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(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): 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(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): 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(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): 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(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): 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(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): 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(values: readonly [T1 | PromiseLike, T2 | PromiseLike]): 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(values: readonly (T | PromiseLike)[]): Promise; + all(values: T): Promise<{ -readonly [P in keyof T]: Awaited }>; // see: lib.es2015.iterable.d.ts // all(values: Iterable>): Promise; @@ -101,7 +29,7 @@ interface PromiseConstructor { * @param values An array of Promises. * @returns A new Promise. */ - race(values: readonly T[]): Promise ? U : T>; + race(values: T): Promise>; // see: lib.es2015.iterable.d.ts // race(values: Iterable): Promise ? U : T>; diff --git a/src/lib/es2020.promise.d.ts b/src/lib/es2020.promise.d.ts index a996a99603..a1b408ff8f 100644 --- a/src/lib/es2020.promise.d.ts +++ b/src/lib/es2020.promise.d.ts @@ -17,8 +17,7 @@ interface PromiseConstructor { * @param values An array of Promises. * @returns A new Promise. */ - allSettled(values: T): - Promise<{ -readonly [P in keyof T]: PromiseSettledResult ? U : T[P]> }>; + allSettled(values: T): Promise<{ -readonly [P in keyof T]: PromiseSettledResult> }>; /** * 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(values: Iterable): Promise ? U : T>[]>; + allSettled(values: Iterable>): Promise>[]>; } diff --git a/src/lib/es2021.promise.d.ts b/src/lib/es2021.promise.d.ts index d18a165814..ef9fdeda98 100644 --- a/src/lib/es2021.promise.d.ts +++ b/src/lib/es2021.promise.d.ts @@ -19,5 +19,12 @@ interface PromiseConstructor { * @param values An array or iterable of Promises. * @returns A new Promise. */ - any(values: (T | PromiseLike)[] | Iterable>): Promise + any(values: T): Promise>; + + /** + * 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(values: Iterable>): Promise> } diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 1d78da7dd6..93fd3986e8 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1472,6 +1472,19 @@ interface Promise { catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; } +/** + * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`. + */ +type Awaited = + 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 : // recursively unwrap the value + never : // the argument to `then` was not callable. + T : // argument was not an object + T; // non-thenable + interface ArrayLike { readonly length: number; readonly [n: number]: T; diff --git a/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt index ce7aaa8db1..7088e40bae 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt @@ -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. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt index 447b8c124f..bd89949dbc 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt @@ -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. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt index 636d8e6e1c..3335bebfa8 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt @@ -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. ~~ diff --git a/tests/baselines/reference/awaitedType.errors.txt b/tests/baselines/reference/awaitedType.errors.txt new file mode 100644 index 0000000000..731e3720f8 --- /dev/null +++ b/tests/baselines/reference/awaitedType.errors.txt @@ -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; + type T2 = Awaited>; + type T3 = Awaited>; + type T4 = Awaited>; + 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; + type T10 = Awaited; + type T11 = Awaited; + type T12 = Awaited>>; + type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful + type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful + type T15 = _Expect> | 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; // 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; // error + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2589: Type instantiation is excessively deep and possibly infinite. + + // https://github.com/microsoft/TypeScript/issues/33562 + type MaybePromise = T | Promise | PromiseLike + declare function MaybePromise(value: T): MaybePromise; + + 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) { + // y: string + const y = await x; + } + + async function f5(x: Promise) { + // y: unknown + const y = await x; + } + + async function f6(x: Promise) { + // y: object + const y = await x; + } + + // generic + + async function f7(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 + const y = await x; + } + + async function f8(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 + const y = await x; + } + + async function f9(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 + const y = await x; + } + + async function f10(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 + const y = await x; + } + + async function f11 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 + const y = await x; + } + + async function f12(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 + const y = await x; + } + + async function f13(x: T) { + // NOTE: T belongs to the domain of primitive types + + // y: T + const y = await x; + } + + async function f14(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; + } + + async function f15(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; + } + + async function f16(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; + \ No newline at end of file diff --git a/tests/baselines/reference/awaitedType.js b/tests/baselines/reference/awaitedType.js new file mode 100644 index 0000000000..4c1485c9d0 --- /dev/null +++ b/tests/baselines/reference/awaitedType.js @@ -0,0 +1,262 @@ +//// [awaitedType.ts] +type T1 = Awaited; +type T2 = Awaited>; +type T3 = Awaited>; +type T4 = Awaited>; +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; +type T10 = Awaited; +type T11 = Awaited; +type T12 = Awaited>>; +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +type T15 = _Expect> | 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; // error + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +type T17 = Awaited; // error + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +declare function MaybePromise(value: T): MaybePromise; + +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) { + // y: string + const y = await x; +} + +async function f5(x: Promise) { + // y: unknown + const y = await x; +} + +async function f6(x: Promise) { + // y: object + const y = await x; +} + +// generic + +async function f7(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 + const y = await x; +} + +async function f8(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 + const y = await x; +} + +async function f9(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 + const y = await x; +} + +async function f10(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 + const y = await x; +} + +async function f11 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 + const y = await x; +} + +async function f12(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 + const y = await x; +} + +async function f13(x: T) { + // NOTE: T belongs to the domain of primitive types + + // y: T + const y = await x; +} + +async function f14(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +} + +async function f15(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +} + +async function f16(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; + + +//// [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 + 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 + 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 + 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 + 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 + 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 + 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; +} diff --git a/tests/baselines/reference/awaitedType.symbols b/tests/baselines/reference/awaitedType.symbols new file mode 100644 index 0000000000..31e6093852 --- /dev/null +++ b/tests/baselines/reference/awaitedType.symbols @@ -0,0 +1,396 @@ +=== tests/cases/compiler/awaitedType.ts === +type T1 = Awaited; +>T1 : Symbol(T1, Decl(awaitedType.ts, 0, 0)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T2 = Awaited>; +>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>; +>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>; +>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; +>T9 : Symbol(T9, Decl(awaitedType.ts, 7, 49)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T10 = Awaited; +>T10 : Symbol(T10, Decl(awaitedType.ts, 8, 23)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T11 = Awaited; +>T11 : Symbol(T11, Decl(awaitedType.ts, 9, 26)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T12 = Awaited>>; +>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> | 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> | 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> | 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; // 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; // 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 | Promise | PromiseLike +>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(value: T): MaybePromise; +>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) { +>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) { +>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) { +>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(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 + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 79, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 73, 21)) +} + +async function f8(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 + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 88, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 82, 33)) +} + +async function f9(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 + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 97, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 91, 37)) +} + +async function f10(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 + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 106, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 100, 33)) +} + +async function f11 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 + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 115, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 109, 84)) +} + +async function f12(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 + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 124, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 118, 46)) +} + +async function f13(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(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(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(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; +>_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)) + diff --git a/tests/baselines/reference/awaitedType.types b/tests/baselines/reference/awaitedType.types new file mode 100644 index 0000000000..86d8402812 --- /dev/null +++ b/tests/baselines/reference/awaitedType.types @@ -0,0 +1,352 @@ +=== tests/cases/compiler/awaitedType.ts === +type T1 = Awaited; +>T1 : number + +type T2 = Awaited>; +>T2 : number + +type T3 = Awaited>; +>T3 : number + +type T4 = Awaited>; +>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; +>T9 : any + +type T10 = Awaited; +>T10 : never + +type T11 = Awaited; +>T11 : unknown + +type T12 = Awaited>>; +>T12 : number + +type T13 = _Expect> | 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> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +>T14 : string | number + +type T15 = _Expect> | 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; // 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; // error +>T17 : any + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +>MaybePromise : MaybePromise + +declare function MaybePromise(value: T): MaybePromise; +>MaybePromise : (value: T) => MaybePromise +>value : T + +async function main() { +>main : () => Promise + + 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 : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>Promise : PromiseConstructor +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise] + + MaybePromise(1), +>MaybePromise(1) : 1 | Promise<1> | PromiseLike<1> +>MaybePromise : (value: T) => MaybePromise +>1 : 1 + + MaybePromise('2'), +>MaybePromise('2') : "2" | Promise<"2"> | PromiseLike<"2"> +>MaybePromise : (value: T) => MaybePromise +>'2' : "2" + + MaybePromise(true), +>MaybePromise(true) : true | Promise | PromiseLike +>MaybePromise : (value: T) => MaybePromise +>true : true + + ]) +} + +// non-generic +async function f1(x: string) { +>f1 : (x: string) => Promise +>x : string + + // y: string + const y = await x; +>y : string +>await x : string +>x : string +} + +async function f2(x: unknown) { +>f2 : (x: unknown) => Promise +>x : unknown + + // y: unknown + const y = await x; +>y : unknown +>await x : unknown +>x : unknown +} + +async function f3(x: object) { +>f3 : (x: object) => Promise +>x : object + + // y: object + const y = await x; +>y : object +>await x : object +>x : object +} + +async function f4(x: Promise) { +>f4 : (x: Promise) => Promise +>x : Promise + + // y: string + const y = await x; +>y : string +>await x : string +>x : Promise +} + +async function f5(x: Promise) { +>f5 : (x: Promise) => Promise +>x : Promise + + // y: unknown + const y = await x; +>y : unknown +>await x : unknown +>x : Promise +} + +async function f6(x: Promise) { +>f6 : (x: Promise) => Promise +>x : Promise + + // y: object + const y = await x; +>y : object +>await x : object +>x : Promise +} + +// generic + +async function f7(x: T) { +>f7 : (x: T) => Promise +>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 + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f8(x: T) { +>f8 : (x: T) => Promise +>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 + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f9(x: T) { +>f9 : (x: T) => Promise +>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 + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f10(x: T) { +>f10 : (x: T) => Promise +>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 + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f11 void): void }>(x: T) { +>f11 : void): void; }>(x: T) => Promise +>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 + const y = await x; +>y : unknown +>await x : unknown +>x : T +} + +async function f12(x: T) { +>f12 : (x: T) => Promise +>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 + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f13(x: T) { +>f13 : (x: T) => Promise +>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(x: T) { +>f14 : (x: T) => Promise +>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(x: T) { +>f15 : (x: T) => Promise +>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(x: T) { +>f16 : (x: T) => Promise +>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; +>_Expect : TActual + diff --git a/tests/baselines/reference/awaitedTypeStrictNull.errors.txt b/tests/baselines/reference/awaitedTypeStrictNull.errors.txt new file mode 100644 index 0000000000..aa2007e54e --- /dev/null +++ b/tests/baselines/reference/awaitedTypeStrictNull.errors.txt @@ -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; + type T2 = Awaited>; + type T3 = Awaited>; + type T4 = Awaited>; + 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; + type T10 = Awaited; + type T11 = Awaited; + type T12 = Awaited>>; + type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful + type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful + type T15 = _Expect> | 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; // 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; // error + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2589: Type instantiation is excessively deep and possibly infinite. + + // https://github.com/microsoft/TypeScript/issues/33562 + type MaybePromise = T | Promise | PromiseLike + declare function MaybePromise(value: T): MaybePromise; + + 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; + \ No newline at end of file diff --git a/tests/baselines/reference/awaitedTypeStrictNull.js b/tests/baselines/reference/awaitedTypeStrictNull.js new file mode 100644 index 0000000000..82c1286111 --- /dev/null +++ b/tests/baselines/reference/awaitedTypeStrictNull.js @@ -0,0 +1,58 @@ +//// [awaitedTypeStrictNull.ts] +type T1 = Awaited; +type T2 = Awaited>; +type T3 = Awaited>; +type T4 = Awaited>; +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; +type T10 = Awaited; +type T11 = Awaited; +type T12 = Awaited>>; +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +type T15 = _Expect> | 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; // error + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +type T17 = Awaited; // error + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +declare function MaybePromise(value: T): MaybePromise; + +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; + + +//// [awaitedTypeStrictNull.js] +async function main() { + let aaa; + let bbb; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]); +} diff --git a/tests/baselines/reference/awaitedTypeStrictNull.symbols b/tests/baselines/reference/awaitedTypeStrictNull.symbols new file mode 100644 index 0000000000..b928a63fe6 --- /dev/null +++ b/tests/baselines/reference/awaitedTypeStrictNull.symbols @@ -0,0 +1,171 @@ +=== tests/cases/compiler/awaitedTypeStrictNull.ts === +type T1 = Awaited; +>T1 : Symbol(T1, Decl(awaitedTypeStrictNull.ts, 0, 0)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T2 = Awaited>; +>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>; +>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>; +>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; +>T9 : Symbol(T9, Decl(awaitedTypeStrictNull.ts, 7, 49)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T10 = Awaited; +>T10 : Symbol(T10, Decl(awaitedTypeStrictNull.ts, 8, 23)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T11 = Awaited; +>T11 : Symbol(T11, Decl(awaitedTypeStrictNull.ts, 9, 26)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T12 = Awaited>>; +>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> | 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> | 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> | 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; // 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; // 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 | Promise | PromiseLike +>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(value: T): MaybePromise; +>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; +>_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)) + diff --git a/tests/baselines/reference/awaitedTypeStrictNull.types b/tests/baselines/reference/awaitedTypeStrictNull.types new file mode 100644 index 0000000000..18312dda7c --- /dev/null +++ b/tests/baselines/reference/awaitedTypeStrictNull.types @@ -0,0 +1,134 @@ +=== tests/cases/compiler/awaitedTypeStrictNull.ts === +type T1 = Awaited; +>T1 : number + +type T2 = Awaited>; +>T2 : number + +type T3 = Awaited>; +>T3 : number + +type T4 = Awaited>; +>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; +>T9 : any + +type T10 = Awaited; +>T10 : never + +type T11 = Awaited; +>T11 : unknown + +type T12 = Awaited>>; +>T12 : number + +type T13 = _Expect> | 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> | 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> | 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; // 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; // error +>T17 : any + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +>MaybePromise : MaybePromise + +declare function MaybePromise(value: T): MaybePromise; +>MaybePromise : (value: T) => MaybePromise +>value : T + +async function main() { +>main : () => Promise + + 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 : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>Promise : PromiseConstructor +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise] + + MaybePromise(1), +>MaybePromise(1) : 1 | Promise<1> | PromiseLike<1> +>MaybePromise : (value: T) => MaybePromise +>1 : 1 + + MaybePromise('2'), +>MaybePromise('2') : "2" | Promise<"2"> | PromiseLike<"2"> +>MaybePromise : (value: T) => MaybePromise +>'2' : "2" + + MaybePromise(true), +>MaybePromise(true) : true | Promise | PromiseLike +>MaybePromise : (value: T) => MaybePromise +>true : true + + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; +>_Expect : TActual + diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols index 29a494f4ec..6efd2fdd69 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols @@ -33,9 +33,9 @@ async function countEverything(): Promise { 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 { 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) diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.types b/tests/baselines/reference/correctOrderOfPromiseMethod.types index fe38cd1dfb..8044cf7350 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.types +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.types @@ -30,9 +30,9 @@ async function countEverything(): Promise { >resultB : B[] >await Promise.all([ providerA(), providerB(), ]) : [A[], B[]] >Promise.all([ providerA(), providerB(), ]) : Promise<[A[], B[]]> ->Promise.all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise.all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >Promise : PromiseConstructor ->all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >[ providerA(), providerB(), ] : [Promise, Promise] providerA(), @@ -76,9 +76,9 @@ async function countEverything(): Promise { 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 : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise.all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >Promise : PromiseConstructor ->all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >undefined as readonly ["a", "b", "c"] : readonly ["a", "b", "c"] >undefined : undefined diff --git a/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.errors.txt b/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.errors.txt index e01b5d483c..f0297fe755 100644 --- a/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.errors.txt +++ b/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.errors.txt @@ -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' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'Yadda | Awaited'. ==== 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' is not assignable to type 'T'. +!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Yadda | Awaited'. } interface Yadda { diff --git a/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.types b/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.types index 52de160da5..d401745bbc 100644 --- a/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.types +++ b/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.types @@ -4,14 +4,14 @@ async function foo(x: T): Promise { >x : T let yaddable = await getXOrYadda(x); ->yaddable : T | Yadda ->await getXOrYadda(x) : T | Yadda +>yaddable : Yadda | Awaited +>await getXOrYadda(x) : Yadda | Awaited >getXOrYadda(x) : T | Yadda >getXOrYadda : (x: T) => T | Yadda >x : T return yaddable; ->yaddable : T | Yadda +>yaddable : Yadda | Awaited } interface Yadda { diff --git a/tests/baselines/reference/forAwaitForUnion.types b/tests/baselines/reference/forAwaitForUnion.types index 180197b26e..5598ebf233 100644 --- a/tests/baselines/reference/forAwaitForUnion.types +++ b/tests/baselines/reference/forAwaitForUnion.types @@ -4,7 +4,7 @@ async function f(source: Iterable | AsyncIterable) { >source : Iterable | AsyncIterable for await (const x of source) { ->x : T +>x : Awaited >source : Iterable | AsyncIterable } } diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols index ecf867a2bf..099c576197 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols @@ -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)) diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types index 5ccfc66940..bd2164e99e 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types @@ -409,14 +409,14 @@ type F = () => Promise>; 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 : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>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 : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >Promise : PromiseConstructor ->all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } ->[ { 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 : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>[ { 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"; } diff --git a/tests/baselines/reference/inferenceLimit.symbols b/tests/baselines/reference/inferenceLimit.symbols index 4b7091a058..2c2a43c35b 100644 --- a/tests/baselines/reference/inferenceLimit.symbols +++ b/tests/baselines/reference/inferenceLimit.symbols @@ -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, --, --)) diff --git a/tests/baselines/reference/inferenceLimit.types b/tests/baselines/reference/inferenceLimit.types index 48aa9aeec0..aa49bdd73b 100644 --- a/tests/baselines/reference/inferenceLimit.types +++ b/tests/baselines/reference/inferenceLimit.types @@ -76,9 +76,9 @@ export class BrokenClass { >Promise.all(result.map(populateItems)) .then((orders: Array) => { resolve(orders); }) : Promise >Promise.all(result.map(populateItems)) .then : (onfulfilled?: (value: unknown[]) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise >Promise.all(result.map(populateItems)) : Promise ->Promise.all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise.all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >Promise : PromiseConstructor ->all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >result.map(populateItems) : Promise[] >result.map : (callbackfn: (value: MyModule.MyModel, index: number, array: MyModule.MyModel[]) => U, thisArg?: any) => U[] >result : MyModule.MyModel[] diff --git a/tests/baselines/reference/mappedTypesArraysTuples.js b/tests/baselines/reference/mappedTypesArraysTuples.js index 7bd4b03a6e..16459b6d6c 100644 --- a/tests/baselines/reference/mappedTypesArraysTuples.js +++ b/tests/baselines/reference/mappedTypesArraysTuples.js @@ -58,8 +58,8 @@ let y21 = nonpartial(x21); declare let x22: { a: number | undefined, b?: string[] }; let y22 = nonpartial(x22); -type Awaited = T extends PromiseLike ? U : T; -type Awaitified = { [P in keyof T]: Awaited }; +type __Awaited = T extends PromiseLike ? U : T; +type Awaitified = { [P in keyof T]: __Awaited }; declare function all(...values: T): Promise>; @@ -189,9 +189,9 @@ declare let y22: { a: number; b: string[]; }; -declare type Awaited = T extends PromiseLike ? U : T; +declare type __Awaited = T extends PromiseLike ? U : T; declare type Awaitified = { - [P in keyof T]: Awaited; + [P in keyof T]: __Awaited; }; declare function all(...values: T): Promise>; declare function f1(a: number, b: Promise, c: string[], d: Promise): void; diff --git a/tests/baselines/reference/mappedTypesArraysTuples.symbols b/tests/baselines/reference/mappedTypesArraysTuples.symbols index 48a3979585..ac3ec26462 100644 --- a/tests/baselines/reference/mappedTypesArraysTuples.symbols +++ b/tests/baselines/reference/mappedTypesArraysTuples.symbols @@ -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 extends PromiseLike ? 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 extends PromiseLike ? 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 = { [P in keyof T]: Awaited }; ->Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 57)) +type Awaitified = { [P in keyof T]: __Awaited }; +>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(...values: T): Promise>; ->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, c: string[], d: Promise) { @@ -252,25 +252,25 @@ function f1(a: number, b: Promise, c: string[], d: Promise) { 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)) diff --git a/tests/baselines/reference/mappedTypesArraysTuples.types b/tests/baselines/reference/mappedTypesArraysTuples.types index daa27b7958..082890b009 100644 --- a/tests/baselines/reference/mappedTypesArraysTuples.types +++ b/tests/baselines/reference/mappedTypesArraysTuples.types @@ -152,10 +152,10 @@ let y22 = nonpartial(x22); >nonpartial : (x: Partial) => T >x22 : { a: number | undefined; b?: string[] | undefined; } -type Awaited = T extends PromiseLike ? U : T; ->Awaited : Awaited +type __Awaited = T extends PromiseLike ? U : T; +>__Awaited : __Awaited -type Awaitified = { [P in keyof T]: Awaited }; +type Awaitified = { [P in keyof T]: __Awaited }; >Awaitified : Awaitified declare function all(...values: T): Promise>; diff --git a/tests/baselines/reference/recursiveConditionalTypes.errors.txt b/tests/baselines/reference/recursiveConditionalTypes.errors.txt index e3b07ef897..051137b4e1 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.errors.txt +++ b/tests/baselines/reference/recursiveConditionalTypes.errors.txt @@ -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' is not assignable to type 'Awaited'. +tests/cases/compiler/recursiveConditionalTypes.ts(20,5): error TS2322: Type '__Awaited' is not assignable to type '__Awaited'. 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'. -tests/cases/compiler/recursiveConditionalTypes.ts(22,5): error TS2322: Type 'Awaited' is not assignable to type 'T'. - 'T' could be instantiated with an arbitrary type which could be unrelated to 'Awaited'. +tests/cases/compiler/recursiveConditionalTypes.ts(21,5): error TS2322: Type 'T' is not assignable to type '__Awaited'. +tests/cases/compiler/recursiveConditionalTypes.ts(22,5): error TS2322: Type '__Awaited' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to '__Awaited'. 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' is not assignable to type 'TupleOf'. @@ -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 = + type __Awaited = T extends null | undefined ? T : - T extends PromiseLike ? Awaited : + T extends PromiseLike ? __Awaited : T; type MyPromise = { @@ -39,26 +39,26 @@ tests/cases/compiler/recursiveConditionalTypes.ts(117,9): error TS2345: Argument type InfinitePromise = Promise>; - type P0 = Awaited | null> | undefined>>; - type P1 = Awaited; - type P2 = Awaited>; // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + type P0 = __Awaited | null> | undefined>>; + type P1 = __Awaited; + type P2 = __Awaited>; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2589: Type instantiation is excessively deep and possibly infinite. - function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { + function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { ta = ua; ua = ta; // Error ~~ -!!! error TS2322: Type 'Awaited' is not assignable to type 'Awaited'. +!!! error TS2322: Type '__Awaited' is not assignable to type '__Awaited'. !!! 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'. +!!! error TS2322: Type 'T' is not assignable to type '__Awaited'. tx = ta; // Error ~~ -!!! error TS2322: Type 'Awaited' is not assignable to type 'T'. -!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Awaited'. +!!! error TS2322: Type '__Awaited' is not assignable to type 'T'. +!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to '__Awaited'. } // Flattening arrays diff --git a/tests/baselines/reference/recursiveConditionalTypes.js b/tests/baselines/reference/recursiveConditionalTypes.js index 79ae612a33..1b7cf831fa 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.js +++ b/tests/baselines/reference/recursiveConditionalTypes.js @@ -1,9 +1,9 @@ //// [recursiveConditionalTypes.ts] // Awaiting promises -type Awaited = +type __Awaited = T extends null | undefined ? T : - T extends PromiseLike ? Awaited : + T extends PromiseLike ? __Awaited : T; type MyPromise = { @@ -12,11 +12,11 @@ type MyPromise = { type InfinitePromise = Promise>; -type P0 = Awaited | null> | undefined>>; -type P1 = Awaited; -type P2 = Awaited>; // Error +type P0 = __Awaited | null> | undefined>>; +type P1 = __Awaited; +type P2 = __Awaited>; // Error -function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { +function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { ta = ua; ua = ta; // Error ta = tx; // Error @@ -172,15 +172,15 @@ function f21(x, y) { //// [recursiveConditionalTypes.d.ts] -declare type Awaited = T extends null | undefined ? T : T extends PromiseLike ? Awaited : T; +declare type __Awaited = T extends null | undefined ? T : T extends PromiseLike ? __Awaited : T; declare type MyPromise = { then(f: ((value: T) => U | PromiseLike) | null | undefined): MyPromise; }; declare type InfinitePromise = Promise>; -declare type P0 = Awaited | null> | undefined>>; -declare type P1 = Awaited; -declare type P2 = Awaited>; -declare function f11(tx: T, ta: Awaited, ux: U, ua: Awaited): void; +declare type P0 = __Awaited | null> | undefined>>; +declare type P1 = __Awaited; +declare type P2 = __Awaited>; +declare function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited): void; declare type Flatten = T extends unknown[] ? _Flatten[] : readonly _Flatten[]; declare type _Flatten = T extends readonly (infer U)[] ? _Flatten : T; declare type InfiniteArray = InfiniteArray[]; diff --git a/tests/baselines/reference/recursiveConditionalTypes.symbols b/tests/baselines/reference/recursiveConditionalTypes.symbols index 7d99adb6bd..492184be49 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.symbols +++ b/tests/baselines/reference/recursiveConditionalTypes.symbols @@ -1,23 +1,23 @@ === tests/cases/compiler/recursiveConditionalTypes.ts === // Awaiting promises -type Awaited = ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) ->T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13)) +type __Awaited = +>__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 ? Awaited : ->T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13)) + T extends PromiseLike ? __Awaited : +>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 = { >MyPromise : Symbol(MyPromise, Decl(recursiveConditionalTypes.ts, 5, 6)) @@ -43,44 +43,44 @@ type InfinitePromise = Promise>; >InfinitePromise : Symbol(InfinitePromise, Decl(recursiveConditionalTypes.ts, 9, 1)) >T : Symbol(T, Decl(recursiveConditionalTypes.ts, 11, 21)) -type P0 = Awaited | null> | undefined>>; +type P0 = __Awaited | 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; ->P1 : Symbol(P1, Decl(recursiveConditionalTypes.ts, 13, 83)) ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +type P1 = __Awaited; +>P1 : Symbol(P1, Decl(recursiveConditionalTypes.ts, 13, 85)) +>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) -type P2 = Awaited>; // Error ->P2 : Symbol(P2, Decl(recursiveConditionalTypes.ts, 14, 23)) ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +type P2 = __Awaited>; // 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(tx: T, ta: Awaited, ux: U, ua: Awaited) { ->f11 : Symbol(f11, Decl(recursiveConditionalTypes.ts, 15, 43)) +function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { +>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 diff --git a/tests/baselines/reference/recursiveConditionalTypes.types b/tests/baselines/reference/recursiveConditionalTypes.types index e700f58edd..281a588649 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.types +++ b/tests/baselines/reference/recursiveConditionalTypes.types @@ -1,13 +1,13 @@ === tests/cases/compiler/recursiveConditionalTypes.ts === // Awaiting promises -type Awaited = ->Awaited : Awaited +type __Awaited = +>__Awaited : __Awaited T extends null | undefined ? T : >null : null - T extends PromiseLike ? Awaited : + T extends PromiseLike ? __Awaited : T; type MyPromise = { @@ -23,42 +23,42 @@ type MyPromise = { type InfinitePromise = Promise>; >InfinitePromise : InfinitePromise -type P0 = Awaited | null> | undefined>>; +type P0 = __Awaited | null> | undefined>>; >P0 : string | number | null | undefined >null : null -type P1 = Awaited; +type P1 = __Awaited; >P1 : any -type P2 = Awaited>; // Error +type P2 = __Awaited>; // Error >P2 : any -function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { ->f11 : (tx: T, ta: Awaited, ux: U, ua: Awaited) => void +function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { +>f11 : (tx: T, ta: __Awaited, ux: U, ua: __Awaited) => void >tx : T ->ta : Awaited +>ta : __Awaited >ux : U ->ua : Awaited +>ua : __Awaited ta = ua; ->ta = ua : Awaited ->ta : Awaited ->ua : Awaited +>ta = ua : __Awaited +>ta : __Awaited +>ua : __Awaited ua = ta; // Error ->ua = ta : Awaited ->ua : Awaited ->ta : Awaited +>ua = ta : __Awaited +>ua : __Awaited +>ta : __Awaited ta = tx; // Error >ta = tx : T ->ta : Awaited +>ta : __Awaited >tx : T tx = ta; // Error ->tx = ta : Awaited +>tx = ta : __Awaited >tx : T ->ta : Awaited +>ta : __Awaited } // Flattening arrays diff --git a/tests/cases/compiler/awaitedType.ts b/tests/cases/compiler/awaitedType.ts new file mode 100644 index 0000000000..13c046685f --- /dev/null +++ b/tests/cases/compiler/awaitedType.ts @@ -0,0 +1,161 @@ +// @target: esnext +// @strictNullChecks: false + +type T1 = Awaited; +type T2 = Awaited>; +type T3 = Awaited>; +type T4 = Awaited>; +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; +type T10 = Awaited; +type T11 = Awaited; +type T12 = Awaited>>; +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +type T15 = _Expect> | 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; // error + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +type T17 = Awaited; // error + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +declare function MaybePromise(value: T): MaybePromise; + +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) { + // y: string + const y = await x; +} + +async function f5(x: Promise) { + // y: unknown + const y = await x; +} + +async function f6(x: Promise) { + // y: object + const y = await x; +} + +// generic + +async function f7(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 + const y = await x; +} + +async function f8(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 + const y = await x; +} + +async function f9(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 + const y = await x; +} + +async function f10(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 + const y = await x; +} + +async function f11 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 + const y = await x; +} + +async function f12(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 + const y = await x; +} + +async function f13(x: T) { + // NOTE: T belongs to the domain of primitive types + + // y: T + const y = await x; +} + +async function f14(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +} + +async function f15(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +} + +async function f16(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; diff --git a/tests/cases/compiler/awaitedTypeStrictNull.ts b/tests/cases/compiler/awaitedTypeStrictNull.ts new file mode 100644 index 0000000000..e5726653a5 --- /dev/null +++ b/tests/cases/compiler/awaitedTypeStrictNull.ts @@ -0,0 +1,45 @@ +// @target: esnext +// @strictNullChecks: true + +type T1 = Awaited; +type T2 = Awaited>; +type T3 = Awaited>; +type T4 = Awaited>; +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; +type T10 = Awaited; +type T11 = Awaited; +type T12 = Awaited>>; +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +type T15 = _Expect> | 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; // error + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +type T17 = Awaited; // error + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +declare function MaybePromise(value: T): MaybePromise; + +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; diff --git a/tests/cases/compiler/recursiveConditionalTypes.ts b/tests/cases/compiler/recursiveConditionalTypes.ts index 30d294a4fc..d086b37f30 100644 --- a/tests/cases/compiler/recursiveConditionalTypes.ts +++ b/tests/cases/compiler/recursiveConditionalTypes.ts @@ -4,9 +4,9 @@ // Awaiting promises -type Awaited = +type __Awaited = T extends null | undefined ? T : - T extends PromiseLike ? Awaited : + T extends PromiseLike ? __Awaited : T; type MyPromise = { @@ -15,11 +15,11 @@ type MyPromise = { type InfinitePromise = Promise>; -type P0 = Awaited | null> | undefined>>; -type P1 = Awaited; -type P2 = Awaited>; // Error +type P0 = __Awaited | null> | undefined>>; +type P1 = __Awaited; +type P2 = __Awaited>; // Error -function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { +function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { ta = ua; ua = ta; // Error ta = tx; // Error diff --git a/tests/cases/conformance/types/mapped/mappedTypesArraysTuples.ts b/tests/cases/conformance/types/mapped/mappedTypesArraysTuples.ts index 2c0f7433ea..249d77974c 100644 --- a/tests/cases/conformance/types/mapped/mappedTypesArraysTuples.ts +++ b/tests/cases/conformance/types/mapped/mappedTypesArraysTuples.ts @@ -60,8 +60,8 @@ let y21 = nonpartial(x21); declare let x22: { a: number | undefined, b?: string[] }; let y22 = nonpartial(x22); -type Awaited = T extends PromiseLike ? U : T; -type Awaitified = { [P in keyof T]: Awaited }; +type __Awaited = T extends PromiseLike ? U : T; +type Awaitified = { [P in keyof T]: __Awaited }; declare function all(...values: T): Promise>;