Skip to content

Commit 936a79b

Browse files
yeonjuanjakebaileyrbuckton
authored
Expose TypeChecker. getAwaitedType to public (#59268)
Co-authored-by: Jake Bailey <[email protected]> Co-authored-by: Ron Buckton <[email protected]>
1 parent 577155f commit 936a79b

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

Diff for: src/compiler/types.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -5051,7 +5051,26 @@ export interface TypeChecker {
50515051
getWidenedLiteralType(type: Type): Type;
50525052
/** @internal */
50535053
getPromisedTypeOfPromise(promise: Type, errorNode?: Node): Type | undefined;
5054-
/** @internal */
5054+
/**
5055+
* Gets the "awaited type" of a type.
5056+
*
5057+
* If an expression has a Promise-like type, the "awaited type" of the expression is
5058+
* derived from the type of the first argument of the fulfillment callback for that
5059+
* Promise's `then` method. If the "awaited type" is itself a Promise-like, it is
5060+
* recursively unwrapped in the same manner until a non-promise type is found.
5061+
*
5062+
* If an expression does not have a Promise-like type, its "awaited type" is the type
5063+
* of the expression.
5064+
*
5065+
* If the resulting "awaited type" is a generic object type, then it is wrapped in
5066+
* an `Awaited<T>`.
5067+
*
5068+
* In the event the "awaited type" circularly references itself, or is a non-Promise
5069+
* object-type with a callable `then()` method, an "awaited type" cannot be determined
5070+
* and the value `undefined` will be returned.
5071+
*
5072+
* This is used to reflect the runtime behavior of the `await` keyword.
5073+
*/
50555074
getAwaitedType(type: Type): Type | undefined;
50565075
/** @internal */
50575076
isEmptyAnonymousObjectType(type: Type): boolean;

Diff for: tests/baselines/reference/api/typescript.d.ts

+21
Original file line numberDiff line numberDiff line change
@@ -6121,6 +6121,27 @@ declare namespace ts {
61216121
getBaseTypes(type: InterfaceType): BaseType[];
61226122
getBaseTypeOfLiteralType(type: Type): Type;
61236123
getWidenedType(type: Type): Type;
6124+
/**
6125+
* Gets the "awaited type" of a type.
6126+
*
6127+
* If an expression has a Promise-like type, the "awaited type" of the expression is
6128+
* derived from the type of the first argument of the fulfillment callback for that
6129+
* Promise's `then` method. If the "awaited type" is itself a Promise-like, it is
6130+
* recursively unwrapped in the same manner until a non-promise type is found.
6131+
*
6132+
* If an expression does not have a Promise-like type, its "awaited type" is the type
6133+
* of the expression.
6134+
*
6135+
* If the resulting "awaited type" is a generic object type, then it is wrapped in
6136+
* an `Awaited<T>`.
6137+
*
6138+
* In the event the "awaited type" circularly references itself, or is a non-Promise
6139+
* object-type with a callable `then()` method, an "awaited type" cannot be determined
6140+
* and the value `undefined` will be returned.
6141+
*
6142+
* This is used to reflect the runtime behavior of the `await` keyword.
6143+
*/
6144+
getAwaitedType(type: Type): Type | undefined;
61246145
getReturnTypeOfSignature(signature: Signature): Type;
61256146
getNullableType(type: Type, flags: TypeFlags): Type;
61266147
getNonNullableType(type: Type): Type;

0 commit comments

Comments
 (0)