Skip to content

Expose Checker.getAwaitedType on the unstable API - #64000

Open
Baptiste Jamin (baptistejamin) wants to merge 1 commit into
microsoft:mainfrom
baptistejamin:api/getAwaitedType
Open

Expose Checker.getAwaitedType on the unstable API#64000
Baptiste Jamin (baptistejamin) wants to merge 1 commit into
microsoft:mainfrom
baptistejamin:api/getAwaitedType

Conversation

@baptistejamin

Copy link
Copy Markdown

getAwaitedType already exists on the TypeScript 6 checker (ts.TypeChecker.getAwaitedType) and internally in the Go checker, but it is not wired through typescript/unstable. This PR exports it on the JS API so callers can get the type of await expr.

Behavior matches the existing checker:

  • unwraps thenables recursively (Promise<string>string, Promise<Promise<number>>number)
  • returns the input type when it is not thenable
  • returns undefined for a circular thenable
  • wraps generic Promise<T> as Awaited<T> when needed

This is needed by typescript-eslint (discriminateAnyType, no-unsafe-return) and other tools that still call checker.getAwaitedType.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI balanced review requested due to automatic review settings August 25, 2026 12:41
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Aug 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes getAwaitedType through the unstable synchronous and asynchronous TypeScript APIs.

Changes:

  • Adds checker and protocol support for awaited-type requests.
  • Implements sync and async client methods with nullable results.
  • Tests promise unwrapping, non-thenables, nesting, and recursive thenables.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tsc/internal/checker/exports.go Exports the internal awaited-type operation.
tsc/internal/api/session.go Handles awaited-type API requests.
tsc/internal/api/proto.go Registers the new protocol method.
packages/typescript/src/api/proto.generated.ts Adds generated protocol typing.
packages/typescript/src/api/sync/api.ts Exposes the synchronous checker method.
packages/typescript/src/api/async/api.ts Exposes the asynchronous checker method.
packages/typescript/test/sync/api.test.ts Tests synchronous behavior.
packages/typescript/test/async/api.test.ts Tests asynchronous behavior.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@baptistejamin

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants