From 904a6e1a7f124b091276a2359effe981ef98bc38 Mon Sep 17 00:00:00 2001 From: YeonJuan Date: Sun, 14 Jul 2024 23:05:13 +0900 Subject: [PATCH 1/4] Expose TypeChecker. getAwaitedType to public --- src/compiler/types.ts | 1 - tests/baselines/reference/api/typescript.d.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6d8a864c30f7f..333ee59fcc4c7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4968,7 +4968,6 @@ export interface TypeChecker { getWidenedLiteralType(type: Type): Type; /** @internal */ getPromisedTypeOfPromise(promise: Type, errorNode?: Node): Type | undefined; - /** @internal */ getAwaitedType(type: Type): Type | undefined; /** @internal */ isEmptyAnonymousObjectType(type: Type): boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index fecf389b0c2c1..02b0574a090a6 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6070,6 +6070,7 @@ declare namespace ts { getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; getWidenedType(type: Type): Type; + getAwaitedType(type: Type): Type | undefined; getReturnTypeOfSignature(signature: Signature): Type; getNullableType(type: Type, flags: TypeFlags): Type; getNonNullableType(type: Type): Type; From b6a5f20c5d4e766989ac2880bb82e5c5d374865e Mon Sep 17 00:00:00 2001 From: YeonJuan Date: Sat, 20 Jul 2024 23:11:42 +0900 Subject: [PATCH 2/4] add jsdocs --- src/compiler/types.ts | 10 ++++++++++ tests/baselines/reference/api/typescript.d.ts | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 333ee59fcc4c7..c3866dfe58dba 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4968,6 +4968,16 @@ export interface TypeChecker { getWidenedLiteralType(type: Type): Type; /** @internal */ getPromisedTypeOfPromise(promise: Type, errorNode?: Node): Type | undefined; + /** + * Gets the "awaited type" of a type. + * + * The "awaited type" of an expression is its "promised type" if the expression is a + * Promise-like type; otherwise, it is the type of the expression. If the "promised + * 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. + */ getAwaitedType(type: Type): Type | undefined; /** @internal */ isEmptyAnonymousObjectType(type: Type): boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 02b0574a090a6..6c6a7ff7b64b8 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6070,6 +6070,16 @@ declare namespace ts { getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; getWidenedType(type: Type): Type; + /** + * Gets the "awaited type" of a type. + * + * The "awaited type" of an expression is its "promised type" if the expression is a + * Promise-like type; otherwise, it is the type of the expression. If the "promised + * 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. + */ getAwaitedType(type: Type): Type | undefined; getReturnTypeOfSignature(signature: Signature): Type; getNullableType(type: Type, flags: TypeFlags): Type; From 1539c81872539390b35749b2ac74e616d8c844e2 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:43:04 -0700 Subject: [PATCH 3/4] Update src/compiler/types.ts Co-authored-by: Ron Buckton --- src/compiler/types.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c3866dfe58dba..5868bb5f772a3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4971,10 +4971,20 @@ export interface TypeChecker { /** * Gets the "awaited type" of a type. * - * The "awaited type" of an expression is its "promised type" if the expression is a - * Promise-like type; otherwise, it is the type of the expression. If the "promised - * type" is itself a Promise-like, the "promised type" is recursively unwrapped until a - * non-promise type is found. + * If an expression has a Promise-like type, the "awaited type" of the expression is + * derived from the type of the first argument of the fulfillment callback for that + * Promise's `then` method. If the "awaited type" is itself a Promise-like, it is + * recursively unwrapped in the same manner until a non-promise type is found. + * + * If an expression does not have a Promise-like type, its "awaited type" is the type + * of the expression. + * + * If the resulting "awaited type" is a generic object type, then it is wrapped in + * an `Awaited`. + * + * In the event the "awaited type" circularly references itself, or is a non-Promise + * object-type with a callable `then()` method, an "awaited type" cannot be determined + * and the value `undefined` will be returned. * * This is used to reflect the runtime behavior of the `await` keyword. */ From 86961f036b8135bc45d8dedfdb86b54cdf4149fe Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:44:19 -0700 Subject: [PATCH 4/4] Update baseline --- tests/baselines/reference/api/typescript.d.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 882ce9284f565..4705789bd75d3 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6124,10 +6124,20 @@ declare namespace ts { /** * Gets the "awaited type" of a type. * - * The "awaited type" of an expression is its "promised type" if the expression is a - * Promise-like type; otherwise, it is the type of the expression. If the "promised - * type" is itself a Promise-like, the "promised type" is recursively unwrapped until a - * non-promise type is found. + * If an expression has a Promise-like type, the "awaited type" of the expression is + * derived from the type of the first argument of the fulfillment callback for that + * Promise's `then` method. If the "awaited type" is itself a Promise-like, it is + * recursively unwrapped in the same manner until a non-promise type is found. + * + * If an expression does not have a Promise-like type, its "awaited type" is the type + * of the expression. + * + * If the resulting "awaited type" is a generic object type, then it is wrapped in + * an `Awaited`. + * + * In the event the "awaited type" circularly references itself, or is a non-Promise + * object-type with a callable `then()` method, an "awaited type" cannot be determined + * and the value `undefined` will be returned. * * This is used to reflect the runtime behavior of the `await` keyword. */