microsoft / microsoft/TypeScript

Please document compiler APIs

Open
#34,890 2 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Docs
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Would it be possible to get some documentation on the compiler APIs?

I am working on some TypeScript tooling, and I am using ts.createSourceFile() to get the AST for a TypeScript source file. However, the tree in SourceFile.statements is missing some information. For example, I need to know the type of an Expression when a PropertyDeclaration only has an initializer but no declared type. I have tried TypeChecker.getContextualType() but it always returns undefined; also the implementation doesn't look right. There are internal methods like TypeChecker.getTypeOfExpression() that look promising, but they are not visible. Also I read some mention of 'bindings', but I haven't found a way to get them.

Another example is type resolution: When I encounter a TypeNode or something similar within the AST, I usually need to know about its declaration: Where does it come from? Is it local? Where is it imported from? Of course I can write that myself with some effort, but surely such logic already exists within the compiler, I just don't know where.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the compiler API areas named in the issue: ts.createSourceFile(), SourceFile.statements, TypeChecker.getContextualType(), getTypeOfExpression(), bindings, and type resolution. Document the supported public APIs for retrieving expression types and declarations, including how imports and local declarations are identified; done means these workflows are clearly explained for TypeScript tooling authors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.