Revert 'awaited' type (#37610)

This commit is contained in:
Ron Buckton
2020-03-25 18:39:45 -07:00
committed by GitHub
parent 84a3252e76
commit 4fc4c4e3d6
111 changed files with 1823 additions and 4716 deletions

View File

@@ -686,7 +686,6 @@ namespace ts {
const literalTypes = createMap<LiteralType>();
const indexedAccessTypes = createMap<IndexedAccessType>();
const substitutionTypes = createMap<SubstitutionType>();
const awaitedTypes = createMap<AwaitedType>();
const evolvingArrayTypes: EvolvingArrayType[] = [];
const undefinedProperties = createMap<Symbol>() as UnderscoreEscapedMap<Symbol>;
@@ -4271,11 +4270,6 @@ namespace ts {
context.approximateLength += 2;
return createIndexedAccessTypeNode(objectTypeNode, indexTypeNode);
}
if (type.flags & TypeFlags.Awaited) {
const awaitedTypeNode = typeToTypeNodeHelper((<AwaitedType>type).awaitedType, context);
context.approximateLength += 9;
return createTypeOperatorNode(SyntaxKind.AwaitedKeyword, awaitedTypeNode);
}
if (type.flags & TypeFlags.Conditional) {
const checkTypeNode = typeToTypeNodeHelper((<ConditionalType>type).checkType, context);
const saveInferTypeParameters = context.inferTypeParameters;
@@ -10124,10 +10118,6 @@ namespace ts {
constraintDepth--;
return result;
}
if (t.flags & TypeFlags.Awaited) {
const basePromiseType = getBaseConstraint((<AwaitedType>t).awaitedType);
return basePromiseType ? getAwaitedType(basePromiseType) : undefined;
}
if (t.flags & TypeFlags.Substitution) {
return getBaseConstraint((<SubstitutionType>t).substitute);
}
@@ -12460,9 +12450,6 @@ namespace ts {
case SyntaxKind.ReadonlyKeyword:
links.resolvedType = getTypeFromTypeNode(node.type);
break;
case SyntaxKind.AwaitedKeyword:
links.resolvedType = getAwaitedType(getTypeFromTypeNode(node.type)) ?? unknownType;
break;
default:
throw Debug.assertNever(node.operator);
}
@@ -14022,9 +14009,6 @@ namespace ts {
if (flags & TypeFlags.Conditional) {
return getConditionalTypeInstantiation(<ConditionalType>type, combineTypeMappers((<ConditionalType>type).mapper, mapper));
}
if (flags & TypeFlags.Awaited) {
return getAwaitedType(instantiateType((<AwaitedType>type).awaitedType, mapper)) ?? unknownType;
}
if (flags & TypeFlags.Substitution) {
const maybeVariable = instantiateType((<SubstitutionType>type).baseType, mapper);
if (maybeVariable.flags & TypeFlags.TypeVariable) {
@@ -15832,8 +15816,7 @@ namespace ts {
if (outofbandVarianceMarkerHandler) {
originalHandler = outofbandVarianceMarkerHandler;
outofbandVarianceMarkerHandler = onlyUnreliable => {
propagatingVarianceFlags |=
onlyUnreliable ? RelationComparisonResult.ReportsUnreliable : RelationComparisonResult.ReportsUnmeasurable;
propagatingVarianceFlags |= onlyUnreliable ? RelationComparisonResult.ReportsUnreliable : RelationComparisonResult.ReportsUnmeasurable;
return originalHandler!(onlyUnreliable);
};
}
@@ -15964,17 +15947,6 @@ namespace ts {
}
}
}
else if (target.flags & TypeFlags.Awaited && source.flags & TypeFlags.Awaited) {
const targetType = (<AwaitedType>target).awaitedType;
const sourceType = instantiateType((<AwaitedType>source).awaitedType, makeFunctionTypeMapper(reportUnreliableMarkers));
// An `awaited S` is related to an `awaited T` if `S` is related to `T`:
//
// S <: T ⇒ awaited S <: awaited T
//
if (result = isRelatedTo(sourceType, targetType, reportErrors)) {
return result;
}
}
else if (isGenericMappedType(target)) {
// A source type T is related to a target type { [P in X]: T[P] }
const template = getTemplateTypeFromMappedType(target);
@@ -16093,21 +16065,6 @@ namespace ts {
}
}
}
else if (source.flags & TypeFlags.Awaited) {
// An `awaited S` is related to `T` if `awaited C` is related to `T`, where `C` is the
// constraint of `S`:
//
// S <: C ^ awaited C <: T ⇒ awaited S <: T
//
// For example `awaited Promise<number>` is assignable to `number`.
const constraint = getConstraintOfType((<AwaitedType>source).awaitedType);
const awaitedConstraint = constraint && getAwaitedType(constraint);
if (awaitedConstraint) {
if (result = isRelatedTo(awaitedConstraint, target, reportErrors)) {
return result;
}
}
}
else {
// An empty object type is related to any mapped type that includes a '?' modifier.
if (relation !== subtypeRelation && relation !== strictSubtypeRelation && isPartialMappedType(target) && isEmptyObjectType(source)) {
@@ -16988,11 +16945,13 @@ namespace ts {
variance = VarianceFlags.Independent;
}
outofbandVarianceMarkerHandler = oldHandler;
if (unmeasurable) {
variance |= VarianceFlags.Unmeasurable;
}
if (unreliable) {
variance |= VarianceFlags.Unreliable;
if (unmeasurable || unreliable) {
if (unmeasurable) {
variance |= VarianceFlags.Unmeasurable;
}
if (unreliable) {
variance |= VarianceFlags.Unreliable;
}
}
variances.push(variance);
}
@@ -18347,9 +18306,6 @@ namespace ts {
inferFromTypes(getTrueTypeFromConditionalType(<ConditionalType>source), getTrueTypeFromConditionalType(<ConditionalType>target));
inferFromTypes(getFalseTypeFromConditionalType(<ConditionalType>source), getFalseTypeFromConditionalType(<ConditionalType>target));
}
else if (source.flags & TypeFlags.Awaited && target.flags & TypeFlags.Awaited) {
inferFromTypes((<AwaitedType>source).awaitedType, (<AwaitedType>target).awaitedType);
}
else if (target.flags & TypeFlags.Conditional) {
const savePriority = priority;
priority |= contravariant ? InferencePriority.ContravariantConditional : 0;
@@ -18357,10 +18313,6 @@ namespace ts {
inferToMultipleTypes(source, targetTypes, target.flags);
priority = savePriority;
}
else if (target.flags & TypeFlags.Awaited) {
inferFromTypes(source, (<AwaitedType>target).awaitedType);
inferFromTypes(source, createPromiseLikeType((<AwaitedType>target).awaitedType));
}
else if (target.flags & TypeFlags.UnionOrIntersection) {
inferToMultipleTypes(source, (<UnionOrIntersectionType>target).types, target.flags);
}
@@ -18489,32 +18441,10 @@ namespace ts {
return typeVariable;
}
function isPromiseForType(promiseType: Type, promisedType: Type) {
return isThenableType(promiseType) && unwrapAwaitedType(getPromisedTypeOfPromise(promiseType) ?? errorType) === promisedType;
}
function inferToMultipleTypes(source: Type, targets: Type[], targetFlags: TypeFlags) {
let typeVariableCount = 0;
if (targetFlags & TypeFlags.Union) {
let nakedTypeVariable: Type | undefined;
for (const t of targets) {
if (getInferenceInfoForType(t)) {
nakedTypeVariable = t;
typeVariableCount++;
}
}
// To better support backwards compatibility with the new `awaited` type, we detect a target
// union of exactly `T | PromiseLike<T>` (for any compatible `PromiseLike`). When encountered,
// we infer from source to the type parameter `T`, where each type of source is mapped to extract
// the promised type of any promise (e.g., `string | Promise<number>` becomes `string | number`).
if (typeVariableCount === 1 && targets.length === 2) {
for (const t of targets) {
if (!getInferenceInfoForType(t) && isPromiseForType(t, nakedTypeVariable!)) {
inferFromTypes(mapType(source, s => getPromisedTypeOfPromise(s) ?? s), nakedTypeVariable!);
return;
}
}
}
const sources = source.flags & TypeFlags.Union ? (<UnionType>source).types : [source];
const matched = new Array<boolean>(sources.length);
let inferenceCircularity = false;
@@ -18523,7 +18453,11 @@ namespace ts {
// equal priority (i.e. of equal quality) to what we would infer for a naked type
// parameter.
for (const t of targets) {
if (!getInferenceInfoForType(t)) {
if (getInferenceInfoForType(t)) {
nakedTypeVariable = t;
typeVariableCount++;
}
else {
for (let i = 0; i < sources.length; i++) {
const saveInferencePriority = inferencePriority;
inferencePriority = InferencePriority.MaxValue;
@@ -21840,10 +21774,7 @@ namespace ts {
const contextualReturnType = getContextualReturnType(func);
if (contextualReturnType) {
if (functionFlags & FunctionFlags.Async) { // Async function
let contextualAwaitedType = getAwaitedTypeOfPromise(contextualReturnType);
if (contextualAwaitedType && contextualAwaitedType.flags & TypeFlags.Awaited) {
contextualAwaitedType = (<AwaitedType>contextualAwaitedType).awaitedType;
}
const contextualAwaitedType = getAwaitedTypeOfPromise(contextualReturnType);
return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]);
}
return contextualReturnType; // Regular function
@@ -21855,10 +21786,7 @@ namespace ts {
function getContextualTypeForAwaitOperand(node: AwaitExpression): Type | undefined {
const contextualType = getContextualType(node);
if (contextualType) {
let contextualAwaitedType = getAwaitedType(contextualType);
if (contextualAwaitedType && contextualAwaitedType.flags & TypeFlags.Awaited) {
contextualAwaitedType = (<AwaitedType>contextualAwaitedType).awaitedType;
}
const contextualAwaitedType = getAwaitedType(contextualType);
return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]);
}
return undefined;
@@ -26777,7 +26705,7 @@ namespace ts {
const globalPromiseType = getGlobalPromiseType(/*reportErrors*/ true);
if (globalPromiseType !== emptyGenericType) {
// if the promised type is itself a promise, get the underlying type; otherwise, fallback to the promised type
promisedType = unwrapAwaitedType(getAwaitedType(promisedType) || unknownType);
promisedType = getAwaitedType(promisedType) || unknownType;
return createTypeReference(globalPromiseType, [promisedType]);
}
@@ -26789,7 +26717,7 @@ namespace ts {
const globalPromiseLikeType = getGlobalPromiseLikeType(/*reportErrors*/ true);
if (globalPromiseLikeType !== emptyGenericType) {
// if the promised type is itself a promise, get the underlying type; otherwise, fallback to the promised type
promisedType = unwrapAwaitedType(getAwaitedType(promisedType) || unknownType);
promisedType = getAwaitedType(promisedType) || unknownType;
return createTypeReference(globalPromiseLikeType, [promisedType]);
}
@@ -30200,9 +30128,8 @@ namespace ts {
return typeAsPromise.promisedTypeOfPromise;
}
if (isReferenceToType(type, getGlobalPromiseType(/*reportErrors*/ false)) ||
isReferenceToType(type, getGlobalPromiseLikeType(/*reportErrors*/ false))) {
return typeAsPromise.promisedTypeOfPromise = getAwaitedType(getTypeArguments(<GenericType>type)[0], errorNode);
if (isReferenceToType(type, getGlobalPromiseType(/*reportErrors*/ false))) {
return typeAsPromise.promisedTypeOfPromise = getTypeArguments(<GenericType>type)[0];
}
const thenFunction = getTypeOfPropertyOfType(type, "then" as __String)!; // TODO: GH#18217
@@ -30246,30 +30173,6 @@ namespace ts {
return awaitedType || errorType;
}
/**
* Gets or creates an `awaited T` type for a generic type.
*
* The "awaited type" of a generic type cannot be determined until it is instantiated. As
* a result, an `AwaitedType` for the generic type is created that can be instantiated
* or related later.
*/
function getAwaitedTypeForGenericType(type: InstantiableType) {
const typeId = "" + type.id;
let awaitedType = awaitedTypes.get(typeId);
if (!awaitedType) {
awaitedType = <AwaitedType>createType(TypeFlags.Awaited);
awaitedType.awaitedType = type;
awaitedTypes.set(typeId, awaitedType);
}
return awaitedType;
}
function unwrapAwaitedType(type: Type): Type {
return type.flags & TypeFlags.Union ?
mapType(type, unwrapAwaitedType) :
type.flags & TypeFlags.Awaited ? (<AwaitedType>type).awaitedType : type;
}
/**
* Determines whether a type has a callable `then` member.
*/
@@ -30278,33 +30181,6 @@ namespace ts {
return !!thenFunction && getSignaturesOfType(getTypeWithFacts(thenFunction, TypeFacts.NEUndefinedOrNull), SignatureKind.Call).length > 0;
}
/**
* Determines whether a type is a generic type whose base constraint could possibly resolve to a different
* type when awaited. A type is a generic "thenable" type when all of the following conditions are met:
* - The type is a generic object type,
* - AND one of the following conditions are met
* - The type has no base constraint,
* - OR The base constraint of the type is `any`, `unknown`, `object`, or the empty object `{}`,
* - OR The base constraint has a callable `then` member.
* This behavior is not entirely sound, as a `T extends { x: any }` could be instantiated with a
* subtype that has a callable `then`, however this is unlikely in practice and this slightly more unsound
* behavior is much more developer friendly.
*/
function isGenericAwaitableType(type: Type): boolean {
if (isGenericObjectType(type)) {
if (type.flags & TypeFlags.Intersection) {
return some((type as IntersectionType).types, isGenericAwaitableType);
}
const baseConstraint = getBaseConstraintOfType(type);
return !baseConstraint ||
!!(baseConstraint.flags & (TypeFlags.AnyOrUnknown | TypeFlags.NonPrimitive)) ||
baseConstraint === emptyObjectType ||
baseConstraint === emptyGenericType ||
isThenableType(baseConstraint);
}
return false;
}
/**
* Gets the "awaited type" of a type.
*
@@ -30313,24 +30189,13 @@ namespace ts {
* type" is itself a Promise-like, the "promised type" is recursively unwrapped until a
* non-promise type is found.
*
* This is used to reflect the runtime behavior of the `await` keyword and the `awaited T`
* type.
* This is used to reflect the runtime behavior of the `await` keyword.
*/
function getAwaitedType(type: Type, errorNode?: Node, diagnosticMessage?: DiagnosticMessage, arg0?: string | number): Type | undefined {
if (isTypeAny(type)) {
return type;
}
// If the type is already an awaited type, return it.
//
// For example:
//
// awaited T -> awaited T
//
if (type.flags & TypeFlags.Awaited) {
return type;
}
const typeAsAwaitable = <PromiseOrAwaitableType>type;
if (typeAsAwaitable.awaitedTypeOfType) {
return typeAsAwaitable.awaitedTypeOfType;
@@ -30338,41 +30203,11 @@ namespace ts {
// For a union, get a union of the awaited types of each constituent.
//
// For example:
//
// awaited (number | string) -> number | string
// awaited (number | Promise<string>) -> number | string
// awaited (T | string) -> awaited T | string
// awaited (T | Promise<string>) -> awaited T | string
// awaited (T | Promise<never>) -> awaited T
// awaited (T | U) -> awaited T | awaited U
//
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 {
// If the type is already an awaited type, return it.
//
// For example:
//
// awaited T -> awaited T
//
if (type.flags & TypeFlags.Awaited) {
return type;
}
// We cannot resolve the awaited type for a type variable until it is instantiated. As
// such, we create an `awaited T` type that can either be instantiated or related later.
//
// For example:
//
// T -> awaited T
//
if (isGenericAwaitableType(type)) {
return getAwaitedTypeForGenericType(<TypeVariable>type);
}
const typeAsAwaitable = <PromiseOrAwaitableType>type;
if (typeAsAwaitable.awaitedTypeOfType) {
return typeAsAwaitable.awaitedTypeOfType;
@@ -32615,7 +32450,7 @@ namespace ts {
const isGenerator = !!(functionFlags & FunctionFlags.Generator);
const isAsync = !!(functionFlags & FunctionFlags.Async);
return isGenerator ? getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, isAsync) || errorType :
isAsync ? unwrapAwaitedType(getAwaitedType(returnType) || errorType) :
isAsync ? getPromisedTypeOfPromise(returnType) || errorType :
returnType;
}
@@ -32654,7 +32489,7 @@ namespace ts {
else if (getReturnTypeFromAnnotation(func)) {
const unwrappedReturnType = unwrapReturnType(returnType, functionFlags);
const unwrappedExprType = functionFlags & FunctionFlags.Async
? unwrapAwaitedType(checkAwaitedType(exprType, node, Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member))
? checkAwaitedType(exprType, node, Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member)
: exprType;
if (unwrappedReturnType) {
// If the function has a return type, but promisedType is

View File

@@ -939,8 +939,8 @@ namespace ts {
}
export function createTypeOperatorNode(type: TypeNode): TypeOperatorNode;
export function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.AwaitedKeyword, type: TypeNode): TypeOperatorNode;
export function createTypeOperatorNode(operatorOrType: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.AwaitedKeyword | TypeNode, type?: TypeNode) {
export function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode;
export function createTypeOperatorNode(operatorOrType: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | TypeNode, type?: TypeNode) {
const node = createSynthesizedNode(SyntaxKind.TypeOperator) as TypeOperatorNode;
node.operator = typeof operatorOrType === "number" ? operatorOrType : SyntaxKind.KeyOfKeyword;
node.type = parenthesizeElementTypeMember(typeof operatorOrType === "number" ? type! : operatorOrType);

View File

@@ -3297,7 +3297,7 @@ namespace ts {
return finishNode(postfix);
}
function parseTypeOperator(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.AwaitedKeyword) {
function parseTypeOperator(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {
const node = <TypeOperatorNode>createNode(SyntaxKind.TypeOperator);
parseExpected(operator);
node.operator = operator;
@@ -3320,7 +3320,6 @@ namespace ts {
case SyntaxKind.KeyOfKeyword:
case SyntaxKind.UniqueKeyword:
case SyntaxKind.ReadonlyKeyword:
case SyntaxKind.AwaitedKeyword:
return parseTypeOperator(operator);
case SyntaxKind.InferKeyword:
return parseInferType();

View File

@@ -146,7 +146,6 @@ namespace ts {
yield: SyntaxKind.YieldKeyword,
async: SyntaxKind.AsyncKeyword,
await: SyntaxKind.AwaitKeyword,
awaited: SyntaxKind.AwaitedKeyword,
of: SyntaxKind.OfKeyword,
};

View File

@@ -107,7 +107,6 @@ namespace ts {
| SyntaxKind.YieldKeyword
| SyntaxKind.AsyncKeyword
| SyntaxKind.AwaitKeyword
| SyntaxKind.AwaitedKeyword
| SyntaxKind.OfKeyword;
export type JsxTokenSyntaxKind =
@@ -262,7 +261,6 @@ namespace ts {
AnyKeyword,
AsyncKeyword,
AwaitKeyword,
AwaitedKeyword,
BooleanKeyword,
ConstructorKeyword,
DeclareKeyword,
@@ -1320,7 +1318,7 @@ namespace ts {
export interface TypeOperatorNode extends TypeNode {
kind: SyntaxKind.TypeOperator;
operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.AwaitedKeyword;
operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword;
type: TypeNode;
}
@@ -4352,7 +4350,6 @@ namespace ts {
Conditional = 1 << 24, // T extends U ? X : Y
Substitution = 1 << 25, // Type parameter substitution
NonPrimitive = 1 << 26, // intrinsic object type
Awaited = 1 << 27, // awaited T
/* @internal */
AnyOrUnknown = Any | Unknown,
@@ -4382,7 +4379,7 @@ namespace ts {
UnionOrIntersection = Union | Intersection,
StructuredType = Object | Union | Intersection,
TypeVariable = TypeParameter | IndexedAccess,
InstantiableNonPrimitive = TypeVariable | Conditional | Substitution | Awaited,
InstantiableNonPrimitive = TypeVariable | Conditional | Substitution,
InstantiablePrimitive = Index,
Instantiable = InstantiableNonPrimitive | InstantiablePrimitive,
StructuredOrInstantiable = StructuredType | Instantiable,
@@ -4827,11 +4824,6 @@ namespace ts {
substitute: Type; // Type to substitute for type parameter
}
// awaited T (TypeFlags.Awaited)
export interface AwaitedType extends InstantiableType {
awaitedType: Type;
}
/* @internal */
export const enum JsxReferenceKind {
Component,

View File

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

View File

@@ -10,7 +10,7 @@ interface PromiseConstructor {
* a resolve callback used to resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*/
new <T>(executor: (resolve: (value?: T | PromiseLike<T> | awaited T) => void, reject: (reason?: any) => void) => void): Promise<T>;
new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
@@ -18,7 +18,7 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[awaited T1, awaited T2, awaited T3, awaited T4, awaited T5, awaited T6, awaited T7, awaited T8, awaited T9, awaited T10]>;
all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
@@ -26,63 +26,7 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[awaited T1, awaited T2, awaited T3, awaited T4, awaited T5, awaited T6, awaited T7, awaited T8, awaited T9]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[awaited T1, awaited T2, awaited T3, awaited T4, awaited T5, awaited T6, awaited T7, awaited T8]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[awaited T1, awaited T2, awaited T3, awaited T4, awaited T5, awaited T6, awaited T7]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[awaited T1, awaited T2, awaited T3, awaited T4, awaited T5, awaited T6]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[awaited T1, awaited T2, awaited T3, awaited T4, awaited T5]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[awaited T1, awaited T2, awaited T3, awaited T4]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[awaited T1, awaited T2, awaited T3]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[awaited T1, awaited T2]>;
all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
@@ -90,7 +34,7 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: awaited T[P] }>;
all<T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
@@ -98,10 +42,58 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T>(values: readonly (T | PromiseLike<T>)[]): Promise<(awaited T)[]>;
all<T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
// see: lib.es2015.iterable.d.ts
// all<T>(values: Iterable<T | PromiseLike<T>>): Promise<(awaited T)[]>;
// all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
@@ -109,24 +101,24 @@ interface PromiseConstructor {
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T>(values: readonly (T | PromiseLike<T>)[]): Promise<awaited T>;
race<T>(values: readonly T[]): Promise<T extends PromiseLike<infer U> ? U : T>;
// see: lib.es2015.iterable.d.ts
// race<T>(values: Iterable<T | PromiseLike<T>>): Promise<awaited T>;
// race<T>(values: Iterable<T>): Promise<T extends PromiseLike<infer U> ? U : T>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject<T = never>(reason?: any): Promise<awaited T>;
reject<T = never>(reason?: any): Promise<T>;
/**
* Creates a new resolved promise for the provided value.
* @param value A promise.
* @returns A promise whose internal state matches the provided promise.
*/
resolve<T>(value: T | PromiseLike<T>): Promise<awaited T>;
resolve<T>(value: T | PromiseLike<T>): Promise<T>;
/**
* Creates a new resolved promise .

View File

@@ -8,5 +8,5 @@ interface Promise<T> {
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
* @returns A Promise for the completion of the callback.
*/
finally(onfinally?: (() => void | PromiseLike<void>) | undefined | null): Promise<awaited T>
finally(onfinally?: (() => void) | undefined | null): Promise<T>
}

View File

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

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

@@ -1378,7 +1378,7 @@ declare type PropertyDecorator = (target: Object, propertyKey: string | symbol)
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
declare type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
declare type PromiseConstructorLike = new <T>(executor: (resolve: (value?: T | PromiseLike<T> | awaited T) => void, reject: (reason?: any) => void) => void) => PromiseLike<T>;
declare type PromiseConstructorLike = new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) => PromiseLike<T>;
interface PromiseLike<T> {
/**
@@ -1387,7 +1387,7 @@ interface PromiseLike<T> {
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: awaited T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<awaited TResult1 | awaited TResult2>;
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
}
/**
@@ -1400,14 +1400,14 @@ interface Promise<T> {
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: awaited T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<awaited TResult1 | awaited TResult2>;
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
/**
* Attaches a callback for only the rejection of the Promise.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of the callback.
*/
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<awaited T | awaited TResult>;
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
}
interface ArrayLike<T> {

View File

@@ -19,5 +19,5 @@ interface PromiseConstructor {
* @param values An array or iterable of Promises.
* @returns A new Promise.
*/
any<T>(values: (T | PromiseLike<T>)[] | Iterable<T | PromiseLike<T>>): Promise<awaited T>
any<T>(values: (T | PromiseLike<T>)[] | Iterable<T | PromiseLike<T>>): Promise<T>
}

View File

@@ -1043,9 +1043,6 @@ namespace ts.codefix {
else if (genericType.flags & TypeFlags.UnionOrIntersection) {
return flatMap((genericType as UnionOrIntersectionType).types, t => inferTypeParameters(t, usageType, typeParameter));
}
else if (genericType.flags & TypeFlags.Awaited) {
return inferTypeParameters((<AwaitedType>genericType).awaitedType, usageType, typeParameter);
}
else if (getObjectFlags(genericType) & ObjectFlags.Reference && getObjectFlags(usageType) & ObjectFlags.Reference) {
// this is wrong because we need a reference to the targetType to, so we can check that it's also a reference
const genericArgs = checker.getTypeArguments(genericType as TypeReference);
@@ -1062,7 +1059,6 @@ namespace ts.codefix {
}
const genericSigs = checker.getSignaturesOfType(genericType, SignatureKind.Call);
const usageSigs = checker.getSignaturesOfType(usageType, SignatureKind.Call);
// allow for multiple overloads of `then`.
if (genericSigs.length === 1 && usageSigs.length === 1) {
return inferFromSignatures(genericSigs[0], usageSigs[0], typeParameter);
}