dsherret / dsherret/ts-morph

Can ts-morph work with typescript interface directly, not via files?

Open
#1,300 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

I need to extract from typescript interface into a js object. I have a function which does exactly that

```
const getKeys = (intName: string): string[] => {
const project = new Project();
const sourceFile = project.addSourceFileAtPath(`./${path}/${intName}.ts`);
const node = sourceFile.getInterface(intName)!;
const allKeys = node.getProperties().map((p) => p.getName());
return allKeys;
};
```

But the problem is, that it requires the interface to be the default export of a seperate file. Ideally i want to provide this function not the file address, but the interface itself, it might look something like this

`getKeys()`

Is this possible to do with ts-morph?

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the Project, addSourceFileAtPath, getInterface, and interface-node APIs used in the getKeys example. Determine whether the requested interface input fits an existing entry point or requires a broader API design; done means the supported approach is documented and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devtools
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.