Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose TypeChecker. getAwaitedType to public #59268

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5051,7 +5051,26 @@ export interface TypeChecker {
getWidenedLiteralType(type: Type): Type;
/** @internal */
getPromisedTypeOfPromise(promise: Type, errorNode?: Node): Type | undefined;
/** @internal */
/**
* Gets the "awaited type" of a type.
*
* 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<T>`.
*
* 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.
*/
getAwaitedType(type: Type): Type | undefined;
jakebailey marked this conversation as resolved.
Show resolved Hide resolved
/** @internal */
isEmptyAnonymousObjectType(type: Type): boolean;
Expand Down
21 changes: 21 additions & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6121,6 +6121,27 @@ declare namespace ts {
getBaseTypes(type: InterfaceType): BaseType[];
getBaseTypeOfLiteralType(type: Type): Type;
getWidenedType(type: Type): Type;
/**
* Gets the "awaited type" of a type.
*
* 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<T>`.
*
* 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.
*/
getAwaitedType(type: Type): Type | undefined;
getReturnTypeOfSignature(signature: Signature): Type;
getNullableType(type: Type, flags: TypeFlags): Type;
getNonNullableType(type: Type): Type;
Expand Down
Loading