[api] Add getSymbol(decl) - #64571
Merged
Andrew Branch (andrewbranch) merged 3 commits intoOct 1, 2026
Merged
Conversation
Copilot started reviewing on behalf of
Andrew Branch (andrewbranch)
October 1, 2026 16:30
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Several tests enforce reference equality after disposal or cache clearing despite the newly documented absence of that guarantee.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Adds binder-symbol lookup for remote declarations without requiring a type checker.
Changes:
- Adds the
getSymbol(declaration)protocol and sync/async APIs. - Associates source files and symbol caches with their owning API.
- Adds symbol lookup, caching, lifecycle, and batching tests.
| File | Description |
|---|---|
.github/skills/api-client/SKILL.md |
Documents cache-lifetime identity guarantees. |
tsc/internal/api/session.go |
Handles declaration-symbol requests. |
tsc/internal/api/session_createsourcefile_test.go |
Tests server-side lookup. |
tsc/internal/api/proto.go |
Defines the protocol method and parameters. |
packages/typescript/src/api/async/api.ts |
Implements the async API and ownership changes. |
packages/typescript/src/api/sync/api.ts |
Implements the sync and generator APIs. |
packages/typescript/src/api/node/node.ts |
Records source-file API ownership. |
packages/typescript/src/api/sourceFileCache.ts |
Adds declaration-symbol caches. |
packages/typescript/src/api/proto.generated.ts |
Updates generated protocol types. |
packages/typescript/test/async/api.test.ts |
Tests async behavior and lifetimes. |
packages/typescript/test/sync/api.test.ts |
Tests sync behavior and lifetimes. |
packages/typescript/test/sync/api-generators.test.ts |
Tests generator and batching parity. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Wesley Wigham (weswigham)
approved these changes
Oct 1, 2026
Wesley Wigham (weswigham)
left a comment
Member
There was a problem hiding this comment.
Pretty sure we need to expose Checker.getMergedSymbol alongside this (well, also for API compat since we used to export it in TS6), since binder symbols are inherently unmerged, so not-so-useful for globals, unless you're only looking for the globals made in a single file. Do you wanna do that as another followup?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Follow-up to #64518. This was going to be the last, but I decided to split it up further.
This PR exposes the direct analog of TS 6’s
declaration.symbolproperty—i.e., access from a Declaration node to its unmerged, binder-produced symbol. Previously,checker.getSymbolAtLocationwas kind of the only way to get a declaration's symbol, and that has some weird, unintuitive behavior.Being able to access binder symbols without a type checker means you can now access symbols from files created with
api.createSourceFile:For convenient access in utility functions, there's also a top-level
getSymbolexport so you can do this without passing around theapi:Why not
decl.getSymbol()?I really wanted (and really tried) to do this, but because there's a sync
Symboltype and an asyncSymboltype, tying that into the AST types directly would mean generating three parallel AST definitions¹:This is possible, and it would fix #64483 at the same time. It might be worth it, but has some rough edges. Mainly, it means you would need dedicated
isnode guard variants for sync and async remote nodes per-kind. When you use a normal guard, that removes the “remoteness” narrowing already applied:You need instead to import the guard from the sync or async module and use the
.Remoterefinement guard:If you try to make the guard signatures more clever, to preserve narrowings already applied, they tend to break in confusing ways in higher order.
This may all be worth doing, still, but I wanted to separate it out for further discussion. A version of this PR with the sync/async remote specializations applied can be viewed at https://github.com/microsoft/TypeScript/compare/main...andrewbranch:remote-ast-types?expand=1
¹ Using a complicated conditional type also works, but makes errors and hover info completely unreadable.