ts-morph icon indicating copy to clipboard operation
ts-morph copied to clipboard

Goto declaration from argument parameter

Open avin-kavish opened this issue 3 years ago • 1 comments

I want to check the type of a parameter of a function and navigate to the declaration if it's within the local project. So far I've gotten the type with,

fn.getParameters().forEach(param => {
  const type = param.getType()

  // goto dec of type
})

How do I process the declaration of the type from here?

avin-kavish avatar Jul 23 '22 04:07 avin-kavish

I had trouble with this too recently. Documentation on the Node/Type/Symbol concepts would be helpful to me as well, but this seems to be working:

for (const decl of type.getSymbol().getDeclarations()) {
  // ...
}

I'm not so sure about checking if it's local to the project. Currently I'm doing that by keeping a list of exported declarations.

donmccurdy avatar May 07 '23 22:05 donmccurdy