Can't get JSDoc text for type alias property
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:
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.
I figured it out, I'm accessing the related PropertySignature node and get the docs from there, like this more or less:
symbol.getDeclarations()[0].getStructure().docs
Of course, it needs the Node.isPropertySignature type guard to make sure that's what it actually is.
There's also:
Node.isJSDocable(declaration)
@diegohaz ah, that's a good one, thanks