Compiler API: Expose More from typescript.d.ts
See original GitHub issueTypeScript Version: 2.9.0-dev.20180426
While Traversing the TypeScript AST of a source file, there have been a number of helpful things I’ve found by extending ts.*
from typescript.d.ts
and I would like it if these could be exposed (or not marked /* @internal */
).
Search Terms: typescript.d.ts Node.locals Symbol.parent getContainingFunction isAssignmentTarget
Code
declare namespace ts {
interface Node {
/* @internal */ readonly locals?: SymbolTable; // Locals associated with node (initialized by binding)
}
interface Symbol {
/* @internal */ readonly parent?: Symbol; // Parent symbol
}
function getContainingFunction(node: Node): SignatureDeclaration | undefined;
function isAssignmentTarget(node: Node): boolean;
}
Note:
- Added
readonly
forNode#locals
&Symbol#parent
- For
Symbol#parent
, the goal is: given the symbol for a method (e.g.,methodSymbol
forNumber#toString
) find where that method is defined (e.g.,Number
)… maybeprogram.getTypeChecker().getSymbolAtLocation(methodSymbol.valueDeclaration.parent)
is what is “supposed” to be used instead? - For
ts.getContainingFunction()
it seems more appropriate to have a return type ofSignatureDeclaration | undefined
instead ofSignatureDeclaration
Related Issues: #15841
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
TypeScript Compiler and Compiler API (Part 2) | by Sunny Sun
TypeScript Compiler API is a hidden gem. The compiler API exposes extremely powerful tools to process TypeScript code programmatically, and ...
Read more >Documentation - Modules .d.ts - TypeScript
Types in Modules Now the type of the array propagates into the ArrayMetadata type. The types which are exported can then be re-used...
Read more >Processing TypeScript using TypeScript - Convinced Coder
One of the interesting things about TypeScript is that it exposes a compiler API that you can use to process TypeScript code ...
Read more >Parsing d.ts files using typescript compiler-Week 1 GSoC'21
Now we not only can make typescript compiler to execute our typescript files but we can also import it as a module in...
Read more >How can I use the TS Compiler API to find where a variable ...
For resolving module names, use ts.resolveModuleName , as recommended on this TS issue. Here is the signature, from typescript.d.ts :
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@granmoe, take a look at
TypeChecker#getSymbolsInScope
(you can get its instance from theprogram
).I second
symbol.parent
! It’s very hard to operate on symbol trees without it.