Currently, I am utilizing ts-morph library which makes use of the TS Compiler API.
Here is an example of my code:
export type Foo = string
export const foo: Foo = 'bar'
Whenever I try to find the type for the export of foo
, it returns string
. However, what I actually need is the type alias declaration type.
The Node type of the export foo
is a VariableDeclaration. Through this, I discovered a way to reach the TypeReferenceNode. Once there, I found a method to retrieve the name of the reference, such as "Foo"
. But, I am unsure how to progress from this name to locate the type alias declaration. Let's assume we are unaware of where the "Foo"
type alias is located. How can this be determined dynamically?