dsherret / dsherret/ts-morph

Get resolved type (like the language server does)

Open
#1,346 3 comments 6 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

Sorry if this doesn't belong here but I'm not able to find any discussion forum for `ts-morph`. Please direct me if there is one.

What I'd like is a fully resolved type, similar when you hover over an identifier in VSCode.
![image](https://user-images.githubusercontent.com/586716/198564076-a95d3168-ebca-48cc-b21f-d1ca2edef99c.png)

What I've tried:
```ts
for (const node of nodesOfInterest) {
const id = node.getFirstChildByKind(tsm.SyntaxKind.Identifier);

const defs = inProject
.getLanguageService()
.compilerObject.getDefinitionAndBoundSpan(
node.compilerNode.getSourceFile().fileName,
id.compilerNode.pos
);
console.log(
node.compilerNode.getSourceFile().fileName,
id.compilerNode.pos,
id.compilerNode.text,
defs
);

// defs is always either undefined or empty
}
```

I've tried `getDefinitionAndBoundSpan`, `getTypeDefinitionAtPosition` and `getDefinitionAtPosition`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.