dsherret / dsherret/ts-morph

Add support for Symbol.getDocumentationComment

Open
#1,428 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Is your feature request related to a problem? Please describe.**

When trying to access the documentation comment on a declaration (not the jsdoc tags, just the beginning part before the tags), there doesn't seem to be any easy way to do this with ts-morph. However, the compiler node has a perfect function for this on `ts.Symbol` called `getDocumentationComment`.

For example, you could do the following:

```typescript
const typeChecker = project.getTypeChecker().compilerObject;
const docComments = symbol.compilerSymbol.getDocumentationComment(typeChecker);
const docCommentString = ts.displayPartsToString(docComments);
```

**Describe the solution you'd like**

Ideally, ts-morph would provide a way to do this natively. Something like this:

```typescript
const docComments = symbol.getDocumentationComment(project.getTypeChecker());
const docCommentString = ts.displayPartsToString(docComments);
```

**Describe alternatives you've considered**

All of the alternatives with leading/trivia comments seem to be limited in either when you can use them or how they interpret the comment text (e.g. they leave extra asterisks).

Contributor guide

Open the contributing guide

Research direction

Start by tracing the ts-morph symbol API and its compilerSymbol access, then compare it with TypeScript's ts.Symbol.getDocumentationComment and the project.getTypeChecker() entry point. Done means callers can retrieve a declaration's documentation comment natively and convert the returned parts to the expected string without using compiler internals directly.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.