When using the ts compiler api how to get the comments from the return of a function declaration?

20 views Asked by At

When using the compiler api, the AST gets a FunctionDeclaration, and there you can get the signatures, symbol and parameters, and in these I can get the comments using the TypeChecker, but for some reason when trying to do that using the type from the getReturnType from a signature I get undefined from the symbol so I can't get comments for it.

const name = symbol.getName();
const stringType = this._checker.typeToString(type);
const documentation = ts.displayPartsToString(signature.getDocumentationComment(this._checker));
const parameters = signature.getParameters().map((parameter) => this._parameter(parameter));
const returns = this._returns(signature.getReturnType());

where this._returns is:

private _returns(type: ts.Type) {
    const stringType = this._checker.typeToString(type);
    const documentation = ts.displayPartsToString(type.getSymbol()?.getDocumentationComment(this._checker));

    return new SerializedReturn(stringType, documentation);
};
0

There are 0 answers