dsherret / dsherret/ts-morph

Is it possible to track the infer type of Promise?

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

Description

Hi. I try to find all nodes that belong to a Promise type.

Can I do it using ts-morph?

In my example, I have a promise with `unknown` type. that makes `findMe` variable to be `unknown` as well.

```
class Foo {
some() {
const doWork = new Promise((res, req) => { res(true) });
doWork.then(findMe => {

});
}
}
```
So is it possible to find that connection in typescript ast? something like "findAllReferences" of type? something like this?
```
const node: UnknownKeyword;
project.getLanguageService().findReferencesAsNodes(node) // output: [Identifier (getText === findMe) ]

```

Because I want to track the `T` of that Promise and change all the nodes that belongs to this type.

Contributor guide

Open the contributing guide

Research direction

Start with the Promise example and the proposed findReferencesAsNodes call, then review how the TypeScript language service resolves types and references. Done means establishing whether the connection from Promise to findMe can be tracked and documenting or implementing the supported approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.