Skip to content

[Question]: How to get a function's type signature (and not "typeof myFunction") #907

@stacey-gammon

Description

@stacey-gammon

I'm using ts-morph to create API documentation, and I'm collecting type signatures. I have two functions defined like so:

export function aFunction(a: string): string {
  return 'hi';
}

export const bFun = (a: string) => { return 'hi'; }

I'm using node.getType().getText() to grab the signature. This works on the arrow function, but it doesn't on the FunctionDeclaration. Using the ast debugger I can see the information I want, but node.getType().getText() gives me typeof aFunction, which is not what I want.

Screen Shot 2020-12-17 at 1 39 35 PM

I'm assuming this information must be extractible somehow since you are displaying it in the ast viewer.

Any ideas? :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions