dsherret / dsherret/ts-morph

Can't get JSDoc text for type alias property

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

Description

**Describe the bug**

I can't seem to obtain the JSDoc text for a type alias property. `getProperties` return an array of `Symbol`, and `Symbol` doesn't expose a `getJsDocs` method, which seems weird to me since it does expose the `getJsDocsTags` method.

Version: 16.0.0

**To Reproduce**

This is my code:

```ts
import { Project } from "ts-morph";

const TSCONFIG_FILE_PATH = "./tsconfig.json";

const project = new Project({ tsConfigFilePath: TSCONFIG_FILE_PATH });

const iconTypesFile = project.getSourceFile("src/components/icon/types.ts");

const iconOptionsType = iconTypesFile
?.getTypeAliasOrThrow("AtlasIconOptions")
.getType();

const iconOptionsProperties = iconOptionsType?.getProperties();

const extractedProperties = iconOptionsProperties?.map((p) => ({
name: p.getName(),
type: p.getValueDeclaration()?.getType(),
jsDocsText: "TODO", // <- I can't use p.getJsDocs() here for some reason
jsDocsTags: p
.getJsDocTags()
.map((tag) => ({ name: tag.getName(), text: tag.getText() })),
}));

extractedProperties?.forEach((x) => console.log(x));
```

The referenced file contains the type, which is a plain type literal with a bunch of properties that have JSDoc comments.

**Expected behavior**

The `getJsDocs` method is available and I can obtain the text.

Contributor guide

Open the contributing guide

Research direction

Start with the getProperties/getJsDocTags path in the reproduction and inspect the type alias in src/components/icon/types.ts. Done when JSDoc text for its properties can be obtained through the public API and the reproduction no longer needs the TODO placeholder.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.