Skip to content

Expose Checker.getAwaitedType on the unstable API - #64000

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

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

@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 30, 2026
@typescript-automation

Copy link
Copy Markdown

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@mrazauskas

Copy link
Copy Markdown
Contributor

This got added in #64264

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants